Skip to content

Commit 6a0678a

Browse files
arndbtytso
authored andcommitted
ext4: super: extend timestamps to 40 bits
The inode timestamps use 34 bits in ext4, but the various timestamps in the superblock are limited to 32 bits. If every user accesses these as 'unsigned', then this is good until year 2106, but it seems better to extend this a bit further in the process of removing the deprecated get_seconds() function. This adds another byte for each timestamp in the superblock, making them long enough to store timestamps beyond what is in the inodes, which seems good enough here (in ocfs2, they are already 64-bit wide, which is appropriate for a new layout). I did not modify e2fsprogs, which obviously needs the same change to actually interpret future timestamps correctly. Signed-off-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent b42d1d6 commit 6a0678a

3 files changed

Lines changed: 55 additions & 12 deletions

File tree

‎fs/ext4/ext4.h‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1295,7 +1295,14 @@ struct ext4_super_block {
12951295
__le32 s_lpf_ino; /* Location of the lost+found inode */
12961296
__le32 s_prj_quota_inum; /* inode for tracking project quota */
12971297
__le32 s_checksum_seed; /* crc32c(uuid) if csum_seed set */
1298-
__le32 s_reserved[98]; /* Padding to the end of the block */
1298+
__u8 s_wtime_hi;
1299+
__u8 s_mtime_hi;
1300+
__u8 s_mkfs_time_hi;
1301+
__u8 s_lastcheck_hi;
1302+
__u8 s_first_error_time_hi;
1303+
__u8 s_last_error_time_hi;
1304+
__u8 s_pad[2];
1305+
__le32 s_reserved[96]; /* Padding to the end of the block */
12991306
__le32 s_checksum; /* crc32c(superblock) */
13001307
};
13011308

‎fs/ext4/super.c‎

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,24 @@ void ext4_itable_unused_set(struct super_block *sb,
312312
bg->bg_itable_unused_hi = cpu_to_le16(count >> 16);
313313
}
314314

315+
static void __ext4_update_tstamp(__le32 *lo, __u8 *hi)
316+
{
317+
time64_t now = ktime_get_real_seconds();
318+
319+
now = clamp_val(now, 0, (1ull << 40) - 1);
320+
321+
*lo = cpu_to_le32(lower_32_bits(now));
322+
*hi = upper_32_bits(now);
323+
}
324+
325+
static time64_t __ext4_get_tstamp(__le32 *lo, __u8 *hi)
326+
{
327+
return ((time64_t)(*hi) << 32) + le32_to_cpu(*lo);
328+
}
329+
#define ext4_update_tstamp(es, tstamp) \
330+
__ext4_update_tstamp(&(es)->tstamp, &(es)->tstamp ## _hi)
331+
#define ext4_get_tstamp(es, tstamp) \
332+
__ext4_get_tstamp(&(es)->tstamp, &(es)->tstamp ## _hi)
315333

316334
static void __save_error_info(struct super_block *sb, const char *func,
317335
unsigned int line)
@@ -322,11 +340,12 @@ static void __save_error_info(struct super_block *sb, const char *func,
322340
if (bdev_read_only(sb->s_bdev))
323341
return;
324342
es->s_state |= cpu_to_le16(EXT4_ERROR_FS);
325-
es->s_last_error_time = cpu_to_le32(get_seconds());
343+
ext4_update_tstamp(es, s_last_error_time);
326344
strncpy(es->s_last_error_func, func, sizeof(es->s_last_error_func));
327345
es->s_last_error_line = cpu_to_le32(line);
328346
if (!es->s_first_error_time) {
329347
es->s_first_error_time = es->s_last_error_time;
348+
es->s_first_error_time_hi = es->s_last_error_time_hi;
330349
strncpy(es->s_first_error_func, func,
331350
sizeof(es->s_first_error_func));
332351
es->s_first_error_line = cpu_to_le32(line);
@@ -2174,8 +2193,8 @@ static int ext4_setup_super(struct super_block *sb, struct ext4_super_block *es,
21742193
"warning: maximal mount count reached, "
21752194
"running e2fsck is recommended");
21762195
else if (le32_to_cpu(es->s_checkinterval) &&
2177-
(le32_to_cpu(es->s_lastcheck) +
2178-
le32_to_cpu(es->s_checkinterval) <= get_seconds()))
2196+
(ext4_get_tstamp(es, s_lastcheck) +
2197+
le32_to_cpu(es->s_checkinterval) <= ktime_get_real_seconds()))
21792198
ext4_msg(sb, KERN_WARNING,
21802199
"warning: checktime reached, "
21812200
"running e2fsck is recommended");
@@ -2184,7 +2203,7 @@ static int ext4_setup_super(struct super_block *sb, struct ext4_super_block *es,
21842203
if (!(__s16) le16_to_cpu(es->s_max_mnt_count))
21852204
es->s_max_mnt_count = cpu_to_le16(EXT4_DFL_MAX_MNT_COUNT);
21862205
le16_add_cpu(&es->s_mnt_count, 1);
2187-
es->s_mtime = cpu_to_le32(get_seconds());
2206+
ext4_update_tstamp(es, s_mtime);
21882207
ext4_update_dynamic_rev(sb);
21892208
if (sbi->s_journal)
21902209
ext4_set_feature_journal_needs_recovery(sb);
@@ -2875,8 +2894,9 @@ static void print_daily_error_info(struct timer_list *t)
28752894
ext4_msg(sb, KERN_NOTICE, "error count since last fsck: %u",
28762895
le32_to_cpu(es->s_error_count));
28772896
if (es->s_first_error_time) {
2878-
printk(KERN_NOTICE "EXT4-fs (%s): initial error at time %u: %.*s:%d",
2879-
sb->s_id, le32_to_cpu(es->s_first_error_time),
2897+
printk(KERN_NOTICE "EXT4-fs (%s): initial error at time %llu: %.*s:%d",
2898+
sb->s_id,
2899+
ext4_get_tstamp(es, s_first_error_time),
28802900
(int) sizeof(es->s_first_error_func),
28812901
es->s_first_error_func,
28822902
le32_to_cpu(es->s_first_error_line));
@@ -2889,8 +2909,9 @@ static void print_daily_error_info(struct timer_list *t)
28892909
printk(KERN_CONT "\n");
28902910
}
28912911
if (es->s_last_error_time) {
2892-
printk(KERN_NOTICE "EXT4-fs (%s): last error at time %u: %.*s:%d",
2893-
sb->s_id, le32_to_cpu(es->s_last_error_time),
2912+
printk(KERN_NOTICE "EXT4-fs (%s): last error at time %llu: %.*s:%d",
2913+
sb->s_id,
2914+
ext4_get_tstamp(es, s_last_error_time),
28942915
(int) sizeof(es->s_last_error_func),
28952916
es->s_last_error_func,
28962917
le32_to_cpu(es->s_last_error_line));
@@ -4813,7 +4834,7 @@ static int ext4_commit_super(struct super_block *sb, int sync)
48134834
* to complain and force a full file system check.
48144835
*/
48154836
if (!(sb->s_flags & SB_RDONLY))
4816-
es->s_wtime = cpu_to_le32(get_seconds());
4837+
ext4_update_tstamp(es, s_wtime);
48174838
if (sb->s_bdev->bd_part)
48184839
es->s_kbytes_written =
48194840
cpu_to_le64(EXT4_SB(sb)->s_kbytes_written +

‎fs/ext4/sysfs.c‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ typedef enum {
2525
attr_reserved_clusters,
2626
attr_inode_readahead,
2727
attr_trigger_test_error,
28+
attr_first_error_time,
29+
attr_last_error_time,
2830
attr_feature,
2931
attr_pointer_ui,
3032
attr_pointer_atomic,
@@ -182,8 +184,8 @@ EXT4_RW_ATTR_SBI_UI(warning_ratelimit_burst, s_warning_ratelimit_state.burst);
182184
EXT4_RW_ATTR_SBI_UI(msg_ratelimit_interval_ms, s_msg_ratelimit_state.interval);
183185
EXT4_RW_ATTR_SBI_UI(msg_ratelimit_burst, s_msg_ratelimit_state.burst);
184186
EXT4_RO_ATTR_ES_UI(errors_count, s_error_count);
185-
EXT4_RO_ATTR_ES_UI(first_error_time, s_first_error_time);
186-
EXT4_RO_ATTR_ES_UI(last_error_time, s_last_error_time);
187+
EXT4_ATTR(first_error_time, 0444, first_error_time);
188+
EXT4_ATTR(last_error_time, 0444, last_error_time);
187189

188190
static unsigned int old_bump_val = 128;
189191
EXT4_ATTR_PTR(max_writeback_mb_bump, 0444, pointer_ui, &old_bump_val);
@@ -249,6 +251,15 @@ static void *calc_ptr(struct ext4_attr *a, struct ext4_sb_info *sbi)
249251
return NULL;
250252
}
251253

254+
static ssize_t __print_tstamp(char *buf, __le32 lo, __u8 hi)
255+
{
256+
return snprintf(buf, PAGE_SIZE, "%lld",
257+
((time64_t)hi << 32) + le32_to_cpu(lo));
258+
}
259+
260+
#define print_tstamp(buf, es, tstamp) \
261+
__print_tstamp(buf, (es)->tstamp, (es)->tstamp ## _hi)
262+
252263
static ssize_t ext4_attr_show(struct kobject *kobj,
253264
struct attribute *attr, char *buf)
254265
{
@@ -287,6 +298,10 @@ static ssize_t ext4_attr_show(struct kobject *kobj,
287298
atomic_read((atomic_t *) ptr));
288299
case attr_feature:
289300
return snprintf(buf, PAGE_SIZE, "supported\n");
301+
case attr_first_error_time:
302+
return print_tstamp(buf, sbi->s_es, s_first_error_time);
303+
case attr_last_error_time:
304+
return print_tstamp(buf, sbi->s_es, s_last_error_time);
290305
}
291306

292307
return 0;

0 commit comments

Comments
 (0)