Skip to content

Commit

Permalink
nilfs2: change sc_timer from a pointer to an embedded one in struct n…
Browse files Browse the repository at this point in the history
…ilfs_sc_info

In nilfs_segctor_thread(), timer is a local variable allocated on stack. Its
address can't be set to sci->sc_timer and passed in several procedures.

It works now by chance, just because other procedures are called by
nilfs_segctor_thread() directly or indirectly and the stack hasn't been
deallocated yet.

Signed-off-by: Li Hong <[email protected]>
Signed-off-by: Ryusuke Konishi <[email protected]>
  • Loading branch information
swanli authored and konis committed May 10, 2010
1 parent 154ac5a commit fdce895
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
31 changes: 13 additions & 18 deletions fs/nilfs2/segment.c
Original file line number Diff line number Diff line change
Expand Up @@ -2159,9 +2159,9 @@ static int nilfs_segctor_do_construct(struct nilfs_sc_info *sci, int mode)
static void nilfs_segctor_start_timer(struct nilfs_sc_info *sci)
{
spin_lock(&sci->sc_state_lock);
if (sci->sc_timer && !(sci->sc_state & NILFS_SEGCTOR_COMMIT)) {
sci->sc_timer->expires = jiffies + sci->sc_interval;
add_timer(sci->sc_timer);
if (!(sci->sc_state & NILFS_SEGCTOR_COMMIT)) {
sci->sc_timer.expires = jiffies + sci->sc_interval;
add_timer(&sci->sc_timer);
sci->sc_state |= NILFS_SEGCTOR_COMMIT;
}
spin_unlock(&sci->sc_state_lock);
Expand Down Expand Up @@ -2366,9 +2366,7 @@ static void nilfs_segctor_accept(struct nilfs_sc_info *sci)
spin_lock(&sci->sc_state_lock);
sci->sc_seq_accepted = sci->sc_seq_request;
spin_unlock(&sci->sc_state_lock);

if (sci->sc_timer)
del_timer_sync(sci->sc_timer);
del_timer_sync(&sci->sc_timer);
}

/**
Expand All @@ -2394,9 +2392,9 @@ static void nilfs_segctor_notify(struct nilfs_sc_info *sci, int mode, int err)
sci->sc_flush_request &= ~FLUSH_DAT_BIT;

/* re-enable timer if checkpoint creation was not done */
if (sci->sc_timer && (sci->sc_state & NILFS_SEGCTOR_COMMIT) &&
time_before(jiffies, sci->sc_timer->expires))
add_timer(sci->sc_timer);
if ((sci->sc_state & NILFS_SEGCTOR_COMMIT) &&
time_before(jiffies, sci->sc_timer.expires))
add_timer(&sci->sc_timer);
}
spin_unlock(&sci->sc_state_lock);
}
Expand Down Expand Up @@ -2575,13 +2573,10 @@ static int nilfs_segctor_thread(void *arg)
{
struct nilfs_sc_info *sci = (struct nilfs_sc_info *)arg;
struct the_nilfs *nilfs = sci->sc_sbi->s_nilfs;
struct timer_list timer;
int timeout = 0;

init_timer(&timer);
timer.data = (unsigned long)current;
timer.function = nilfs_construction_timeout;
sci->sc_timer = &timer;
sci->sc_timer.data = (unsigned long)current;
sci->sc_timer.function = nilfs_construction_timeout;

/* start sync. */
sci->sc_task = current;
Expand Down Expand Up @@ -2630,7 +2625,7 @@ static int nilfs_segctor_thread(void *arg)
should_sleep = 0;
else if (sci->sc_state & NILFS_SEGCTOR_COMMIT)
should_sleep = time_before(jiffies,
sci->sc_timer->expires);
sci->sc_timer.expires);

if (should_sleep) {
spin_unlock(&sci->sc_state_lock);
Expand All @@ -2639,7 +2634,7 @@ static int nilfs_segctor_thread(void *arg)
}
finish_wait(&sci->sc_wait_daemon, &wait);
timeout = ((sci->sc_state & NILFS_SEGCTOR_COMMIT) &&
time_after_eq(jiffies, sci->sc_timer->expires));
time_after_eq(jiffies, sci->sc_timer.expires));

if (nilfs_sb_dirty(nilfs) && nilfs_sb_need_update(nilfs))
set_nilfs_discontinued(nilfs);
Expand All @@ -2648,8 +2643,6 @@ static int nilfs_segctor_thread(void *arg)

end_thread:
spin_unlock(&sci->sc_state_lock);
del_timer_sync(sci->sc_timer);
sci->sc_timer = NULL;

/* end sync. */
sci->sc_task = NULL;
Expand Down Expand Up @@ -2708,6 +2701,7 @@ static struct nilfs_sc_info *nilfs_segctor_new(struct nilfs_sb_info *sbi)
INIT_LIST_HEAD(&sci->sc_write_logs);
INIT_LIST_HEAD(&sci->sc_gc_inodes);
INIT_LIST_HEAD(&sci->sc_copied_buffers);
init_timer(&sci->sc_timer);

sci->sc_interval = HZ * NILFS_SC_DEFAULT_TIMEOUT;
sci->sc_mjcp_freq = HZ * NILFS_SC_DEFAULT_SR_FREQ;
Expand Down Expand Up @@ -2774,6 +2768,7 @@ static void nilfs_segctor_destroy(struct nilfs_sc_info *sci)

down_write(&sbi->s_nilfs->ns_segctor_sem);

del_timer_sync(&sci->sc_timer);
kfree(sci);
}

Expand Down
2 changes: 1 addition & 1 deletion fs/nilfs2/segment.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ struct nilfs_sc_info {
unsigned long sc_lseg_stime; /* in 1/HZ seconds */
unsigned long sc_watermark;

struct timer_list *sc_timer;
struct timer_list sc_timer;
struct task_struct *sc_task;
};

Expand Down

0 comments on commit fdce895

Please sign in to comment.