summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnd Bergmann <arnd@arndb.de>2018-02-06 18:39:21 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2018-02-06 21:32:45 -0500
commitfb04b91bc2c3a83e9e2ba9c5ce0f0124dd3ffef0 (patch)
tree00e48e16224695ef3eb0cf0b29a57a51a90fea6a
parentca3a45697be3ad59aa8f8f83d0e277b49f4b5680 (diff)
nilfs2: use time64_t internally
The superblock and segment timestamps are used only internally in nilfs2 and can be read out using sysfs. Since we are using the old 'get_seconds()' interface and store the data as timestamps, the behavior differs slightly between 64-bit and 32-bit kernels, the latter will show incorrect timestamps after 2038 in sysfs, and presumably fail completely in 2106 as comparisons go wrong. This changes nilfs2 to use time64_t with ktime_get_real_seconds() to handle timestamps, making the behavior consistent and correct on both 32-bit and 64-bit machines. The on-disk format already uses 64-bit timestamps, so nothing changes there. Link: http://lkml.kernel.org/r/20180122211050.1286441-1-arnd@arndb.de Signed-off-by: Arnd Bergmann <arnd@arndb.de> Acked-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp> Cc: Jens Axboe <axboe@kernel.dk> Cc: Ingo Molnar <mingo@kernel.org> Cc: Jan Kara <jack@suse.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--fs/nilfs2/segbuf.c2
-rw-r--r--fs/nilfs2/segbuf.h4
-rw-r--r--fs/nilfs2/segment.c2
-rw-r--r--fs/nilfs2/segment.h2
-rw-r--r--fs/nilfs2/sufile.c2
-rw-r--r--fs/nilfs2/sufile.h2
-rw-r--r--fs/nilfs2/super.c4
-rw-r--r--fs/nilfs2/sysfs.c21
-rw-r--r--fs/nilfs2/the_nilfs.h8
9 files changed, 23 insertions, 24 deletions
diff --git a/fs/nilfs2/segbuf.c b/fs/nilfs2/segbuf.c
index 6c5009cc4e6f..68cb9e4740b4 100644
--- a/fs/nilfs2/segbuf.c
+++ b/fs/nilfs2/segbuf.c
@@ -130,7 +130,7 @@ int nilfs_segbuf_extend_payload(struct nilfs_segment_buffer *segbuf,
130} 130}
131 131
132int nilfs_segbuf_reset(struct nilfs_segment_buffer *segbuf, unsigned int flags, 132int nilfs_segbuf_reset(struct nilfs_segment_buffer *segbuf, unsigned int flags,
133 time_t ctime, __u64 cno) 133 time64_t ctime, __u64 cno)
134{ 134{
135 int err; 135 int err;
136 136
diff --git a/fs/nilfs2/segbuf.h b/fs/nilfs2/segbuf.h
index 7bbccc099709..10e16935fff6 100644
--- a/fs/nilfs2/segbuf.h
+++ b/fs/nilfs2/segbuf.h
@@ -46,7 +46,7 @@ struct nilfs_segsum_info {
46 unsigned long nfileblk; 46 unsigned long nfileblk;
47 u64 seg_seq; 47 u64 seg_seq;
48 __u64 cno; 48 __u64 cno;
49 time_t ctime; 49 time64_t ctime;
50 sector_t next; 50 sector_t next;
51}; 51};
52 52
@@ -120,7 +120,7 @@ void nilfs_segbuf_map_cont(struct nilfs_segment_buffer *segbuf,
120 struct nilfs_segment_buffer *prev); 120 struct nilfs_segment_buffer *prev);
121void nilfs_segbuf_set_next_segnum(struct nilfs_segment_buffer *, __u64, 121void nilfs_segbuf_set_next_segnum(struct nilfs_segment_buffer *, __u64,
122 struct the_nilfs *); 122 struct the_nilfs *);
123int nilfs_segbuf_reset(struct nilfs_segment_buffer *, unsigned int, time_t, 123int nilfs_segbuf_reset(struct nilfs_segment_buffer *, unsigned int, time64_t,
124 __u64); 124 __u64);
125int nilfs_segbuf_extend_segsum(struct nilfs_segment_buffer *); 125int nilfs_segbuf_extend_segsum(struct nilfs_segment_buffer *);
126int nilfs_segbuf_extend_payload(struct nilfs_segment_buffer *, 126int nilfs_segbuf_extend_payload(struct nilfs_segment_buffer *,
diff --git a/fs/nilfs2/segment.c b/fs/nilfs2/segment.c
index 9f3ffba41533..0953635e7d48 100644
--- a/fs/nilfs2/segment.c
+++ b/fs/nilfs2/segment.c
@@ -2040,7 +2040,7 @@ static int nilfs_segctor_do_construct(struct nilfs_sc_info *sci, int mode)
2040 goto out; 2040 goto out;
2041 2041
2042 /* Update time stamp */ 2042 /* Update time stamp */
2043 sci->sc_seg_ctime = get_seconds(); 2043 sci->sc_seg_ctime = ktime_get_real_seconds();
2044 2044
2045 err = nilfs_segctor_collect(sci, nilfs, mode); 2045 err = nilfs_segctor_collect(sci, nilfs, mode);
2046 if (unlikely(err)) 2046 if (unlikely(err))
diff --git a/fs/nilfs2/segment.h b/fs/nilfs2/segment.h
index 84084a4d9b3e..04634e3e3d58 100644
--- a/fs/nilfs2/segment.h
+++ b/fs/nilfs2/segment.h
@@ -157,7 +157,7 @@ struct nilfs_sc_info {
157 unsigned long sc_blk_cnt; 157 unsigned long sc_blk_cnt;
158 unsigned long sc_datablk_cnt; 158 unsigned long sc_datablk_cnt;
159 unsigned long sc_nblk_this_inc; 159 unsigned long sc_nblk_this_inc;
160 time_t sc_seg_ctime; 160 time64_t sc_seg_ctime;
161 __u64 sc_cno; 161 __u64 sc_cno;
162 unsigned long sc_flags; 162 unsigned long sc_flags;
163 163
diff --git a/fs/nilfs2/sufile.c b/fs/nilfs2/sufile.c
index 1341a41e7b43..c7fa139d50e8 100644
--- a/fs/nilfs2/sufile.c
+++ b/fs/nilfs2/sufile.c
@@ -526,7 +526,7 @@ int nilfs_sufile_mark_dirty(struct inode *sufile, __u64 segnum)
526 * @modtime: modification time (option) 526 * @modtime: modification time (option)
527 */ 527 */
528int nilfs_sufile_set_segment_usage(struct inode *sufile, __u64 segnum, 528int nilfs_sufile_set_segment_usage(struct inode *sufile, __u64 segnum,
529 unsigned long nblocks, time_t modtime) 529 unsigned long nblocks, time64_t modtime)
530{ 530{
531 struct buffer_head *bh; 531 struct buffer_head *bh;
532 struct nilfs_segment_usage *su; 532 struct nilfs_segment_usage *su;
diff --git a/fs/nilfs2/sufile.h b/fs/nilfs2/sufile.h
index 158a9190c8ec..673a891350f4 100644
--- a/fs/nilfs2/sufile.h
+++ b/fs/nilfs2/sufile.h
@@ -35,7 +35,7 @@ int nilfs_sufile_set_alloc_range(struct inode *sufile, __u64 start, __u64 end);
35int nilfs_sufile_alloc(struct inode *, __u64 *); 35int nilfs_sufile_alloc(struct inode *, __u64 *);
36int nilfs_sufile_mark_dirty(struct inode *sufile, __u64 segnum); 36int nilfs_sufile_mark_dirty(struct inode *sufile, __u64 segnum);
37int nilfs_sufile_set_segment_usage(struct inode *sufile, __u64 segnum, 37int nilfs_sufile_set_segment_usage(struct inode *sufile, __u64 segnum,
38 unsigned long nblocks, time_t modtime); 38 unsigned long nblocks, time64_t modtime);
39int nilfs_sufile_get_stat(struct inode *, struct nilfs_sustat *); 39int nilfs_sufile_get_stat(struct inode *, struct nilfs_sustat *);
40ssize_t nilfs_sufile_get_suinfo(struct inode *, __u64, void *, unsigned int, 40ssize_t nilfs_sufile_get_suinfo(struct inode *, __u64, void *, unsigned int,
41 size_t); 41 size_t);
diff --git a/fs/nilfs2/super.c b/fs/nilfs2/super.c
index 3073b646e1ba..6ffeca84d7c3 100644
--- a/fs/nilfs2/super.c
+++ b/fs/nilfs2/super.c
@@ -283,10 +283,10 @@ int nilfs_commit_super(struct super_block *sb, int flag)
283{ 283{
284 struct the_nilfs *nilfs = sb->s_fs_info; 284 struct the_nilfs *nilfs = sb->s_fs_info;
285 struct nilfs_super_block **sbp = nilfs->ns_sbp; 285 struct nilfs_super_block **sbp = nilfs->ns_sbp;
286 time_t t; 286 time64_t t;
287 287
288 /* nilfs->ns_sem must be locked by the caller. */ 288 /* nilfs->ns_sem must be locked by the caller. */
289 t = get_seconds(); 289 t = ktime_get_real_seconds();
290 nilfs->ns_sbwtime = t; 290 nilfs->ns_sbwtime = t;
291 sbp[0]->s_wtime = cpu_to_le64(t); 291 sbp[0]->s_wtime = cpu_to_le64(t);
292 sbp[0]->s_sum = 0; 292 sbp[0]->s_sum = 0;
diff --git a/fs/nilfs2/sysfs.c b/fs/nilfs2/sysfs.c
index 490303e3d517..4b25837e7724 100644
--- a/fs/nilfs2/sysfs.c
+++ b/fs/nilfs2/sysfs.c
@@ -31,7 +31,7 @@ static struct kset *nilfs_kset;
31#define NILFS_SHOW_TIME(time_t_val, buf) ({ \ 31#define NILFS_SHOW_TIME(time_t_val, buf) ({ \
32 struct tm res; \ 32 struct tm res; \
33 int count = 0; \ 33 int count = 0; \
34 time_to_tm(time_t_val, 0, &res); \ 34 time64_to_tm(time_t_val, 0, &res); \
35 res.tm_year += 1900; \ 35 res.tm_year += 1900; \
36 res.tm_mon += 1; \ 36 res.tm_mon += 1; \
37 count = scnprintf(buf, PAGE_SIZE, \ 37 count = scnprintf(buf, PAGE_SIZE, \
@@ -579,7 +579,7 @@ nilfs_segctor_last_seg_write_time_show(struct nilfs_segctor_attr *attr,
579 struct the_nilfs *nilfs, 579 struct the_nilfs *nilfs,
580 char *buf) 580 char *buf)
581{ 581{
582 time_t ctime; 582 time64_t ctime;
583 583
584 down_read(&nilfs->ns_segctor_sem); 584 down_read(&nilfs->ns_segctor_sem);
585 ctime = nilfs->ns_ctime; 585 ctime = nilfs->ns_ctime;
@@ -593,13 +593,13 @@ nilfs_segctor_last_seg_write_time_secs_show(struct nilfs_segctor_attr *attr,
593 struct the_nilfs *nilfs, 593 struct the_nilfs *nilfs,
594 char *buf) 594 char *buf)
595{ 595{
596 time_t ctime; 596 time64_t ctime;
597 597
598 down_read(&nilfs->ns_segctor_sem); 598 down_read(&nilfs->ns_segctor_sem);
599 ctime = nilfs->ns_ctime; 599 ctime = nilfs->ns_ctime;
600 up_read(&nilfs->ns_segctor_sem); 600 up_read(&nilfs->ns_segctor_sem);
601 601
602 return snprintf(buf, PAGE_SIZE, "%llu\n", (unsigned long long)ctime); 602 return snprintf(buf, PAGE_SIZE, "%llu\n", ctime);
603} 603}
604 604
605static ssize_t 605static ssize_t
@@ -607,7 +607,7 @@ nilfs_segctor_last_nongc_write_time_show(struct nilfs_segctor_attr *attr,
607 struct the_nilfs *nilfs, 607 struct the_nilfs *nilfs,
608 char *buf) 608 char *buf)
609{ 609{
610 time_t nongc_ctime; 610 time64_t nongc_ctime;
611 611
612 down_read(&nilfs->ns_segctor_sem); 612 down_read(&nilfs->ns_segctor_sem);
613 nongc_ctime = nilfs->ns_nongc_ctime; 613 nongc_ctime = nilfs->ns_nongc_ctime;
@@ -621,14 +621,13 @@ nilfs_segctor_last_nongc_write_time_secs_show(struct nilfs_segctor_attr *attr,
621 struct the_nilfs *nilfs, 621 struct the_nilfs *nilfs,
622 char *buf) 622 char *buf)
623{ 623{
624 time_t nongc_ctime; 624 time64_t nongc_ctime;
625 625
626 down_read(&nilfs->ns_segctor_sem); 626 down_read(&nilfs->ns_segctor_sem);
627 nongc_ctime = nilfs->ns_nongc_ctime; 627 nongc_ctime = nilfs->ns_nongc_ctime;
628 up_read(&nilfs->ns_segctor_sem); 628 up_read(&nilfs->ns_segctor_sem);
629 629
630 return snprintf(buf, PAGE_SIZE, "%llu\n", 630 return snprintf(buf, PAGE_SIZE, "%llu\n", nongc_ctime);
631 (unsigned long long)nongc_ctime);
632} 631}
633 632
634static ssize_t 633static ssize_t
@@ -728,7 +727,7 @@ nilfs_superblock_sb_write_time_show(struct nilfs_superblock_attr *attr,
728 struct the_nilfs *nilfs, 727 struct the_nilfs *nilfs,
729 char *buf) 728 char *buf)
730{ 729{
731 time_t sbwtime; 730 time64_t sbwtime;
732 731
733 down_read(&nilfs->ns_sem); 732 down_read(&nilfs->ns_sem);
734 sbwtime = nilfs->ns_sbwtime; 733 sbwtime = nilfs->ns_sbwtime;
@@ -742,13 +741,13 @@ nilfs_superblock_sb_write_time_secs_show(struct nilfs_superblock_attr *attr,
742 struct the_nilfs *nilfs, 741 struct the_nilfs *nilfs,
743 char *buf) 742 char *buf)
744{ 743{
745 time_t sbwtime; 744 time64_t sbwtime;
746 745
747 down_read(&nilfs->ns_sem); 746 down_read(&nilfs->ns_sem);
748 sbwtime = nilfs->ns_sbwtime; 747 sbwtime = nilfs->ns_sbwtime;
749 up_read(&nilfs->ns_sem); 748 up_read(&nilfs->ns_sem);
750 749
751 return snprintf(buf, PAGE_SIZE, "%llu\n", (unsigned long long)sbwtime); 750 return snprintf(buf, PAGE_SIZE, "%llu\n", sbwtime);
752} 751}
753 752
754static ssize_t 753static ssize_t
diff --git a/fs/nilfs2/the_nilfs.h b/fs/nilfs2/the_nilfs.h
index 883d732b0259..36da1779f976 100644
--- a/fs/nilfs2/the_nilfs.h
+++ b/fs/nilfs2/the_nilfs.h
@@ -116,7 +116,7 @@ struct the_nilfs {
116 */ 116 */
117 struct buffer_head *ns_sbh[2]; 117 struct buffer_head *ns_sbh[2];
118 struct nilfs_super_block *ns_sbp[2]; 118 struct nilfs_super_block *ns_sbp[2];
119 time_t ns_sbwtime; 119 time64_t ns_sbwtime;
120 unsigned int ns_sbwcount; 120 unsigned int ns_sbwcount;
121 unsigned int ns_sbsize; 121 unsigned int ns_sbsize;
122 unsigned int ns_mount_state; 122 unsigned int ns_mount_state;
@@ -131,8 +131,8 @@ struct the_nilfs {
131 __u64 ns_nextnum; 131 __u64 ns_nextnum;
132 unsigned long ns_pseg_offset; 132 unsigned long ns_pseg_offset;
133 __u64 ns_cno; 133 __u64 ns_cno;
134 time_t ns_ctime; 134 time64_t ns_ctime;
135 time_t ns_nongc_ctime; 135 time64_t ns_nongc_ctime;
136 atomic_t ns_ndirtyblks; 136 atomic_t ns_ndirtyblks;
137 137
138 /* 138 /*
@@ -267,7 +267,7 @@ struct nilfs_root {
267 267
268static inline int nilfs_sb_need_update(struct the_nilfs *nilfs) 268static inline int nilfs_sb_need_update(struct the_nilfs *nilfs)
269{ 269{
270 u64 t = get_seconds(); 270 u64 t = ktime_get_real_seconds();
271 271
272 return t < nilfs->ns_sbwtime || 272 return t < nilfs->ns_sbwtime ||
273 t > nilfs->ns_sbwtime + nilfs->ns_sb_update_freq; 273 t > nilfs->ns_sbwtime + nilfs->ns_sb_update_freq;