Skip to content

Commit fdce895

Browse files
swanlikonis
authored andcommitted
nilfs2: change sc_timer from a pointer to an embedded one in struct nilfs_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 <lihong.hi@gmail.com> Signed-off-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
1 parent 154ac5a commit fdce895

2 files changed

Lines changed: 14 additions & 19 deletions

File tree

‎fs/nilfs2/segment.c‎

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2159,9 +2159,9 @@ static int nilfs_segctor_do_construct(struct nilfs_sc_info *sci, int mode)
21592159
static void nilfs_segctor_start_timer(struct nilfs_sc_info *sci)
21602160
{
21612161
spin_lock(&sci->sc_state_lock);
2162-
if (sci->sc_timer && !(sci->sc_state & NILFS_SEGCTOR_COMMIT)) {
2163-
sci->sc_timer->expires = jiffies + sci->sc_interval;
2164-
add_timer(sci->sc_timer);
2162+
if (!(sci->sc_state & NILFS_SEGCTOR_COMMIT)) {
2163+
sci->sc_timer.expires = jiffies + sci->sc_interval;
2164+
add_timer(&sci->sc_timer);
21652165
sci->sc_state |= NILFS_SEGCTOR_COMMIT;
21662166
}
21672167
spin_unlock(&sci->sc_state_lock);
@@ -2366,9 +2366,7 @@ static void nilfs_segctor_accept(struct nilfs_sc_info *sci)
23662366
spin_lock(&sci->sc_state_lock);
23672367
sci->sc_seq_accepted = sci->sc_seq_request;
23682368
spin_unlock(&sci->sc_state_lock);
2369-
2370-
if (sci->sc_timer)
2371-
del_timer_sync(sci->sc_timer);
2369+
del_timer_sync(&sci->sc_timer);
23722370
}
23732371

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

23962394
/* re-enable timer if checkpoint creation was not done */
2397-
if (sci->sc_timer && (sci->sc_state & NILFS_SEGCTOR_COMMIT) &&
2398-
time_before(jiffies, sci->sc_timer->expires))
2399-
add_timer(sci->sc_timer);
2395+
if ((sci->sc_state & NILFS_SEGCTOR_COMMIT) &&
2396+
time_before(jiffies, sci->sc_timer.expires))
2397+
add_timer(&sci->sc_timer);
24002398
}
24012399
spin_unlock(&sci->sc_state_lock);
24022400
}
@@ -2575,13 +2573,10 @@ static int nilfs_segctor_thread(void *arg)
25752573
{
25762574
struct nilfs_sc_info *sci = (struct nilfs_sc_info *)arg;
25772575
struct the_nilfs *nilfs = sci->sc_sbi->s_nilfs;
2578-
struct timer_list timer;
25792576
int timeout = 0;
25802577

2581-
init_timer(&timer);
2582-
timer.data = (unsigned long)current;
2583-
timer.function = nilfs_construction_timeout;
2584-
sci->sc_timer = &timer;
2578+
sci->sc_timer.data = (unsigned long)current;
2579+
sci->sc_timer.function = nilfs_construction_timeout;
25852580

25862581
/* start sync. */
25872582
sci->sc_task = current;
@@ -2630,7 +2625,7 @@ static int nilfs_segctor_thread(void *arg)
26302625
should_sleep = 0;
26312626
else if (sci->sc_state & NILFS_SEGCTOR_COMMIT)
26322627
should_sleep = time_before(jiffies,
2633-
sci->sc_timer->expires);
2628+
sci->sc_timer.expires);
26342629

26352630
if (should_sleep) {
26362631
spin_unlock(&sci->sc_state_lock);
@@ -2639,7 +2634,7 @@ static int nilfs_segctor_thread(void *arg)
26392634
}
26402635
finish_wait(&sci->sc_wait_daemon, &wait);
26412636
timeout = ((sci->sc_state & NILFS_SEGCTOR_COMMIT) &&
2642-
time_after_eq(jiffies, sci->sc_timer->expires));
2637+
time_after_eq(jiffies, sci->sc_timer.expires));
26432638

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

26492644
end_thread:
26502645
spin_unlock(&sci->sc_state_lock);
2651-
del_timer_sync(sci->sc_timer);
2652-
sci->sc_timer = NULL;
26532646

26542647
/* end sync. */
26552648
sci->sc_task = NULL;
@@ -2708,6 +2701,7 @@ static struct nilfs_sc_info *nilfs_segctor_new(struct nilfs_sb_info *sbi)
27082701
INIT_LIST_HEAD(&sci->sc_write_logs);
27092702
INIT_LIST_HEAD(&sci->sc_gc_inodes);
27102703
INIT_LIST_HEAD(&sci->sc_copied_buffers);
2704+
init_timer(&sci->sc_timer);
27112705

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

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

2771+
del_timer_sync(&sci->sc_timer);
27772772
kfree(sci);
27782773
}
27792774

‎fs/nilfs2/segment.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ struct nilfs_sc_info {
177177
unsigned long sc_lseg_stime; /* in 1/HZ seconds */
178178
unsigned long sc_watermark;
179179

180-
struct timer_list *sc_timer;
180+
struct timer_list sc_timer;
181181
struct task_struct *sc_task;
182182
};
183183

0 commit comments

Comments
 (0)