Re: [PATCH 2/3] reiserfs: use monotonic time for j_trans_start_time

From: Jan Kara
Date: Wed Jun 20 2018 - 04:43:50 EST


On Tue 19-06-18 17:43:14, Arnd Bergmann wrote:
> Using CLOCK_REALTIME time_t timestamps breaks on 32-bit systems
> in 2038, and gives surprising results with a concurrent settimeofday().
>
> This changes the reiserfs journal timestamps to use ktime_get_seconds()
> instead, which makes it use a 64-bit CLOCK_MONOTONIC stamp.
>
> In the procfs output, the monotonic timestamp needs to be converted
> back to CLOCK_REALTIME to keep the existing ABI.
>
> Signed-off-by: Arnd Bergmann <arnd@xxxxxxxx>
...
> diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
> index e39b3910d24d..520f9003c13a 100644
> --- a/fs/reiserfs/procfs.c
> +++ b/fs/reiserfs/procfs.c
> @@ -303,6 +303,10 @@ static int show_journal(struct seq_file *m, void *unused)
> struct reiserfs_sb_info *r = REISERFS_SB(sb);
> struct reiserfs_super_block *rs = r->s_rs;
> struct journal_params *jp = &rs->s_v1.s_journal;
> + ktime_t j_trans_start_ktime = ktime_set(JF(j_trans_start_time), 0);
> +
> + /* print as CLOCK_REALTIME */
> + j_trans_start_ktime = ktime_mono_to_real(j_trans_start_ktime);
>
> seq_printf(m, /* on-disk fields */
> "jp_journal_1st_block: \t%i\n"
> @@ -325,7 +329,7 @@ static int show_journal(struct seq_file *m, void *unused)
> "j_bcount: \t%lu\n"
> "j_first_unflushed_offset: \t%lu\n"
> "j_last_flush_trans_id: \t%u\n"
> - "j_trans_start_time: \t%li\n"
> + "j_trans_start_time: \t%lli\n"
> "j_list_bitmap_index: \t%i\n"
> "j_must_wait: \t%i\n"
> "j_next_full_flush: \t%i\n"
> @@ -366,7 +370,7 @@ static int show_journal(struct seq_file *m, void *unused)
> JF(j_bcount),
> JF(j_first_unflushed_offset),
> JF(j_last_flush_trans_id),
> - JF(j_trans_start_time),
> + ktime_divns(j_trans_start_ktime, NSEC_PER_SEC),

Hum, this looks cumbersome - maybe have a helper function converting
MONOTONIC to REALTIME seconds? Regardless the code looks correct and
reiserfs is old enough that I'm happy someone improves anything there so
I'm OK even with the current code. Feel free to add:

Reviewed-by: Jan Kara <jack@xxxxxxx>

Honza

--
Jan Kara <jack@xxxxxxxx>
SUSE Labs, CR