NILFS_ST_INIT = 0,
NILFS_ST_GC, /* Collecting dirty blocks for GC */
NILFS_ST_FILE,
- NILFS_ST_SKETCH,
NILFS_ST_IFILE,
NILFS_ST_CPFILE,
NILFS_ST_SUFILE,
sci->sc_binfo_ptr = sci->sc_finfo_ptr;
nilfs_segctor_map_segsum_entry(
sci, &sci->sc_binfo_ptr, sizeof(struct nilfs_finfo));
+
+ if (inode->i_sb && !test_bit(NILFS_SC_HAVE_DELTA, &sci->sc_flags))
+ set_bit(NILFS_SC_HAVE_DELTA, &sci->sc_flags);
/* skip finfo */
}
cpu_to_le64(sci->sc_nblk_inc + sci->sc_nblk_this_inc);
raw_cp->cp_create = cpu_to_le64(sci->sc_seg_ctime);
raw_cp->cp_cno = cpu_to_le64(nilfs->ns_cno);
- if (sci->sc_sketch_inode && i_size_read(sci->sc_sketch_inode) > 0)
- nilfs_checkpoint_set_sketch(raw_cp);
+
+ if (test_bit(NILFS_SC_HAVE_DELTA, &sci->sc_flags))
+ nilfs_checkpoint_clear_minor(raw_cp);
+ else
+ nilfs_checkpoint_set_minor(raw_cp);
+
nilfs_write_inode_common(sbi->s_ifile, &raw_cp->cp_ifile_inode, 1);
nilfs_cpfile_put_checkpoint(nilfs->ns_cpfile, nilfs->ns_cno, bh_cp);
return 0;
nilfs_fill_in_file_bmap(ifile, ii);
set_bit(NILFS_I_COLLECTED, &ii->i_state);
}
- if (sci->sc_sketch_inode) {
- ii = NILFS_I(sci->sc_sketch_inode);
- if (test_bit(NILFS_I_DIRTY, &ii->i_state))
- nilfs_fill_in_file_bmap(ifile, ii);
- }
}
/*
sci->sc_stage.scnt = NILFS_ST_DONE;
return 0;
}
- sci->sc_stage.scnt++; /* Fall through */
- case NILFS_ST_SKETCH:
- if (mode == SC_LSEG_SR && sci->sc_sketch_inode) {
- ii = NILFS_I(sci->sc_sketch_inode);
- if (test_bit(NILFS_I_DIRTY, &ii->i_state)) {
- sci->sc_sketch_inode->i_ctime.tv_sec
- = sci->sc_seg_ctime;
- sci->sc_sketch_inode->i_mtime.tv_sec
- = sci->sc_seg_ctime;
- err = nilfs_mark_inode_dirty(
- sci->sc_sketch_inode);
- if (unlikely(err))
- goto break_or_fail;
- }
- err = nilfs_segctor_scan_file(sci,
- sci->sc_sketch_inode,
- &nilfs_sc_file_ops);
- if (unlikely(err))
- goto break_or_fail;
- }
sci->sc_stage.scnt++;
sci->sc_stage.flags |= NILFS_CF_IFILE_STARTED;
/* Fall through */
return err;
}
-static int nilfs_segctor_terminate_segment(struct nilfs_sc_info *sci,
- struct nilfs_segment_buffer *segbuf,
- struct inode *sufile)
-{
- struct nilfs_segment_entry *ent = segbuf->sb_segent;
- int err;
-
- err = nilfs_open_segment_entry(ent, sufile);
- if (unlikely(err))
- return err;
- nilfs_mdt_mark_buffer_dirty(ent->bh_su);
- nilfs_mdt_mark_dirty(sufile);
- nilfs_close_segment_entry(ent, sufile);
-
- list_add_tail(&ent->list, &sci->sc_active_segments);
- segbuf->sb_segent = NULL;
- return 0;
-}
-
static int nilfs_touch_segusage(struct inode *sufile, __u64 segnum)
{
struct buffer_head *bh_su;
struct the_nilfs *nilfs)
{
struct nilfs_segment_buffer *segbuf, *n;
- struct inode *sufile = nilfs->ns_sufile;
__u64 nextnum;
int err;
} else
segbuf = NILFS_FIRST_SEGBUF(&sci->sc_segbufs);
- err = nilfs_segbuf_map(segbuf, nilfs->ns_segnum,
- nilfs->ns_pseg_offset, nilfs);
- if (unlikely(err))
- return err;
+ nilfs_segbuf_map(segbuf, nilfs->ns_segnum, nilfs->ns_pseg_offset,
+ nilfs);
if (segbuf->sb_rest_blocks < NILFS_PSEG_MIN_BLOCKS) {
- err = nilfs_segctor_terminate_segment(sci, segbuf, sufile);
- if (unlikely(err))
- return err;
-
nilfs_shift_to_next_segment(nilfs);
- err = nilfs_segbuf_map(segbuf, nilfs->ns_segnum, 0, nilfs);
+ nilfs_segbuf_map(segbuf, nilfs->ns_segnum, 0, nilfs);
}
sci->sc_segbuf_nblocks = segbuf->sb_rest_blocks;
- err = nilfs_touch_segusage(sufile, segbuf->sb_segnum);
+ err = nilfs_touch_segusage(nilfs->ns_sufile, segbuf->sb_segnum);
if (unlikely(err))
return err;
if (nilfs->ns_segnum == nilfs->ns_nextnum) {
/* Start from the head of a new full segment */
- err = nilfs_sufile_alloc(sufile, &nextnum);
+ err = nilfs_sufile_alloc(nilfs->ns_sufile, &nextnum);
if (unlikely(err))
return err;
} else
list_del_init(&segbuf->sb_list);
nilfs_segbuf_free(segbuf);
}
- return err;
+ return 0;
}
static int nilfs_segctor_extend_segments(struct nilfs_sc_info *sci,
goto failed;
/* map this buffer to region of segment on-disk */
- err = nilfs_segbuf_map(segbuf, prev->sb_nextnum, 0, nilfs);
- if (unlikely(err))
- goto failed_segbuf;
-
+ nilfs_segbuf_map(segbuf, prev->sb_nextnum, 0, nilfs);
sci->sc_segbuf_nblocks += segbuf->sb_rest_blocks;
/* allocate the next next full segment */
if (update_sr) {
nilfs_set_last_segment(nilfs, segbuf->sb_pseg_start,
- segbuf->sb_sum.seg_seq, nilfs->ns_cno);
+ segbuf->sb_sum.seg_seq, nilfs->ns_cno++);
+ sbi->s_super->s_dirt = 1;
+ clear_bit(NILFS_SC_HAVE_DELTA, &sci->sc_flags);
clear_bit(NILFS_SC_DIRTY, &sci->sc_flags);
set_bit(NILFS_SC_SUPER_ROOT, &sci->sc_flags);
} else
spin_unlock(&sbi->s_inode_lock);
}
-/*
- * Nasty routines to manipulate active flags on sufile.
- * These would be removed in a future release.
- */
-static void nilfs_segctor_reactivate_segments(struct nilfs_sc_info *sci,
- struct the_nilfs *nilfs)
-{
- struct nilfs_segment_buffer *segbuf, *last;
- struct nilfs_segment_entry *ent, *n;
- struct inode *sufile = nilfs->ns_sufile;
- struct list_head *head;
-
- last = NILFS_LAST_SEGBUF(&sci->sc_segbufs);
- nilfs_for_each_segbuf_before(segbuf, last, &sci->sc_segbufs) {
- ent = segbuf->sb_segent;
- if (!ent)
- break; /* ignore unmapped segments (should check it?)*/
- nilfs_segment_usage_set_active(ent->raw_su);
- nilfs_close_segment_entry(ent, sufile);
- }
-
- head = &sci->sc_active_segments;
- list_for_each_entry_safe(ent, n, head, list) {
- nilfs_segment_usage_set_active(ent->raw_su);
- nilfs_close_segment_entry(ent, sufile);
- }
-}
-
-static int nilfs_segctor_deactivate_segments(struct nilfs_sc_info *sci,
- struct the_nilfs *nilfs)
-{
- struct nilfs_segment_buffer *segbuf, *last;
- struct nilfs_segment_entry *ent;
- struct inode *sufile = nilfs->ns_sufile;
- int err;
-
- last = NILFS_LAST_SEGBUF(&sci->sc_segbufs);
- nilfs_for_each_segbuf_before(segbuf, last, &sci->sc_segbufs) {
- /*
- * Deactivate ongoing full segments. The last segment is kept
- * active because it is a start point of recovery, and is not
- * relocatable until the super block points to a newer
- * checkpoint.
- */
- ent = segbuf->sb_segent;
- if (!ent)
- break; /* ignore unmapped segments (should check it?)*/
- err = nilfs_open_segment_entry(ent, sufile);
- if (unlikely(err))
- goto failed;
- nilfs_segment_usage_clear_active(ent->raw_su);
- BUG_ON(!buffer_dirty(ent->bh_su));
- }
-
- list_for_each_entry(ent, &sci->sc_active_segments, list) {
- err = nilfs_open_segment_entry(ent, sufile);
- if (unlikely(err))
- goto failed;
- nilfs_segment_usage_clear_active(ent->raw_su);
- WARN_ON(!buffer_dirty(ent->bh_su));
- }
- return 0;
-
- failed:
- nilfs_segctor_reactivate_segments(sci, nilfs);
- return err;
-}
-
-static void nilfs_segctor_bead_completed_segments(struct nilfs_sc_info *sci)
-{
- struct nilfs_segment_buffer *segbuf, *last;
- struct nilfs_segment_entry *ent;
-
- /* move each segbuf->sb_segent to the list of used active segments */
- last = NILFS_LAST_SEGBUF(&sci->sc_segbufs);
- nilfs_for_each_segbuf_before(segbuf, last, &sci->sc_segbufs) {
- ent = segbuf->sb_segent;
- if (!ent)
- break; /* ignore unmapped segments (should check it?)*/
- list_add_tail(&ent->list, &sci->sc_active_segments);
- segbuf->sb_segent = NULL;
- }
-}
-
-static void nilfs_segctor_commit_deactivate_segments(struct nilfs_sc_info *sci,
- struct the_nilfs *nilfs)
-{
- struct nilfs_segment_entry *ent, *n;
-
- list_for_each_entry_safe(ent, n, &sci->sc_active_segments, list) {
- list_del(&ent->list);
- nilfs_close_segment_entry(ent, nilfs->ns_sufile);
- nilfs_free_segment_entry(ent);
- }
-}
-
/*
* Main procedure of segment constructor
*/
if (unlikely(err))
goto failed;
- if (has_sr) {
- err = nilfs_segctor_deactivate_segments(sci, nilfs);
- if (unlikely(err))
- goto failed;
- }
if (sci->sc_stage.flags & NILFS_CF_IFILE_STARTED)
nilfs_segctor_fill_in_file_bmap(sci, sbi->s_ifile);
nilfs_segctor_complete_write(sci);
/* Commit segments */
- nilfs_segctor_bead_completed_segments(sci);
if (has_sr) {
- down_write(&nilfs->ns_sem);
- nilfs_update_last_segment(sbi, 1);
- up_write(&nilfs->ns_sem);
- nilfs_segctor_commit_deactivate_segments(sci, nilfs);
nilfs_segctor_commit_free_segments(sci);
nilfs_segctor_clear_metadata_dirty(sci);
}
} while (sci->sc_stage.scnt != NILFS_ST_DONE);
- /* Clearing sketch data */
- if (has_sr && sci->sc_sketch_inode) {
- if (i_size_read(sci->sc_sketch_inode) == 0)
- clear_bit(NILFS_I_DIRTY,
- &NILFS_I(sci->sc_sketch_inode)->i_state);
- i_size_write(sci->sc_sketch_inode, 0);
- }
out:
nilfs_segctor_destroy_segment_buffers(sci);
nilfs_segctor_check_out_files(sci, sbi);
failed_to_make_up:
if (sci->sc_stage.flags & NILFS_CF_IFILE_STARTED)
nilfs_redirty_inodes(&sci->sc_dirty_files);
- if (has_sr)
- nilfs_segctor_reactivate_segments(sci, nilfs);
failed:
if (nilfs_doing_gc())
if (test_bit(NILFS_SC_SUPER_ROOT, &sci->sc_flags) &&
nilfs_discontinued(nilfs)) {
down_write(&nilfs->ns_sem);
- req->sb_err = nilfs_commit_super(sbi);
+ req->sb_err = nilfs_commit_super(sbi, 0);
up_write(&nilfs->ns_sem);
}
}
}
}
-static int nilfs_segctor_init(struct nilfs_sc_info *sci,
- struct nilfs_recovery_info *ri)
+static int nilfs_segctor_init(struct nilfs_sc_info *sci)
{
- int err;
- struct inode *inode = nilfs_iget(sci->sc_super, NILFS_SKETCH_INO);
-
- sci->sc_sketch_inode = IS_ERR(inode) ? NULL : inode;
- if (sci->sc_sketch_inode)
- i_size_write(sci->sc_sketch_inode, 0);
-
sci->sc_seq_done = sci->sc_seq_request;
- if (ri)
- list_splice_init(&ri->ri_used_segments,
- sci->sc_active_segments.prev);
- err = nilfs_segctor_start_thread(sci);
- if (err) {
- if (ri)
- list_splice_init(&sci->sc_active_segments,
- ri->ri_used_segments.prev);
- if (sci->sc_sketch_inode) {
- iput(sci->sc_sketch_inode);
- sci->sc_sketch_inode = NULL;
- }
- }
- return err;
+ return nilfs_segctor_start_thread(sci);
}
/*
INIT_LIST_HEAD(&sci->sc_dirty_files);
INIT_LIST_HEAD(&sci->sc_segbufs);
INIT_LIST_HEAD(&sci->sc_gc_inodes);
- INIT_LIST_HEAD(&sci->sc_active_segments);
INIT_LIST_HEAD(&sci->sc_cleaning_segments);
INIT_LIST_HEAD(&sci->sc_copied_buffers);
"dirty file(s) after the final construction\n");
nilfs_dispose_list(sbi, &sci->sc_dirty_files, 1);
}
- if (!list_empty(&sci->sc_active_segments))
- nilfs_dispose_segment_list(&sci->sc_active_segments);
if (!list_empty(&sci->sc_cleaning_segments))
nilfs_dispose_segment_list(&sci->sc_cleaning_segments);
WARN_ON(!list_empty(&sci->sc_segbufs));
- if (sci->sc_sketch_inode) {
- iput(sci->sc_sketch_inode);
- sci->sc_sketch_inode = NULL;
- }
down_write(&sbi->s_nilfs->ns_segctor_sem);
kfree(sci);
/**
* nilfs_attach_segment_constructor - attach a segment constructor
* @sbi: nilfs_sb_info
- * @ri: nilfs_recovery_info
*
* nilfs_attach_segment_constructor() allocates a struct nilfs_sc_info,
* initilizes it, and starts the segment constructor.
*
* %-ENOMEM - Insufficient memory available.
*/
-int nilfs_attach_segment_constructor(struct nilfs_sb_info *sbi,
- struct nilfs_recovery_info *ri)
+int nilfs_attach_segment_constructor(struct nilfs_sb_info *sbi)
{
struct the_nilfs *nilfs = sbi->s_nilfs;
int err;
return -ENOMEM;
nilfs_attach_writer(nilfs, sbi);
- err = nilfs_segctor_init(NILFS_SC(sbi), ri);
+ err = nilfs_segctor_init(NILFS_SC(sbi));
if (err) {
nilfs_detach_writer(nilfs, sbi);
kfree(sbi->s_sc_info);