Skip to content

Commit f8b92ba

Browse files
committed
mount: Add mount warning for impending timestamp expiry
The warning reuses the uptime max of 30 years used by settimeofday(). Note that the warning is only emitted for writable filesystem mounts through the mount syscall. Automounts do not have the same warning. Print out the warning in human readable format using the struct tm. After discussion with Arnd Bergmann, we chose to print only the year number. The raw s_time_max is also displayed, and the user can easily decode it e.g. "date -u -d @$((0x7fffffff))". We did not want to consolidate struct rtc_tm and struct tm just to print the date using a format specifier as part of this series. Given that the rtc_tm is not compiled on all architectures, this is not a trivial patch. This can be added in the future. Signed-off-by: Deepa Dinamani <[email protected]> Acked-by: Jeff Layton <[email protected]>
1 parent 3818c19 commit f8b92ba

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

fs/namespace.c

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2463,6 +2463,26 @@ static void set_mount_attributes(struct mount *mnt, unsigned int mnt_flags)
24632463
unlock_mount_hash();
24642464
}
24652465

2466+
static void mnt_warn_timestamp_expiry(struct path *mountpoint, struct vfsmount *mnt)
2467+
{
2468+
struct super_block *sb = mnt->mnt_sb;
2469+
2470+
if (!__mnt_is_readonly(mnt) &&
2471+
(ktime_get_real_seconds() + TIME_UPTIME_SEC_MAX > sb->s_time_max)) {
2472+
char *buf = (char *)__get_free_page(GFP_KERNEL);
2473+
char *mntpath = buf ? d_path(mountpoint, buf, PAGE_SIZE) : ERR_PTR(-ENOMEM);
2474+
struct tm tm;
2475+
2476+
time64_to_tm(sb->s_time_max, 0, &tm);
2477+
2478+
pr_warn("Mounted %s file system at %s supports timestamps until %04ld (0x%llx)\n",
2479+
sb->s_type->name, mntpath,
2480+
tm.tm_year+1900, (unsigned long long)sb->s_time_max);
2481+
2482+
free_page((unsigned long)buf);
2483+
}
2484+
}
2485+
24662486
/*
24672487
* Handle reconfiguration of the mountpoint only without alteration of the
24682488
* superblock it refers to. This is triggered by specifying MS_REMOUNT|MS_BIND
@@ -2488,6 +2508,9 @@ static int do_reconfigure_mnt(struct path *path, unsigned int mnt_flags)
24882508
if (ret == 0)
24892509
set_mount_attributes(mnt, mnt_flags);
24902510
up_write(&sb->s_umount);
2511+
2512+
mnt_warn_timestamp_expiry(path, &mnt->mnt);
2513+
24912514
return ret;
24922515
}
24932516

@@ -2528,6 +2551,9 @@ static int do_remount(struct path *path, int ms_flags, int sb_flags,
25282551
}
25292552
up_write(&sb->s_umount);
25302553
}
2554+
2555+
mnt_warn_timestamp_expiry(path, &mnt->mnt);
2556+
25312557
put_fs_context(fc);
25322558
return err;
25332559
}
@@ -2736,8 +2762,13 @@ static int do_new_mount_fc(struct fs_context *fc, struct path *mountpoint,
27362762
return PTR_ERR(mnt);
27372763

27382764
error = do_add_mount(real_mount(mnt), mountpoint, mnt_flags);
2739-
if (error < 0)
2765+
if (error < 0) {
27402766
mntput(mnt);
2767+
return error;
2768+
}
2769+
2770+
mnt_warn_timestamp_expiry(mountpoint, mnt);
2771+
27412772
return error;
27422773
}
27432774

0 commit comments

Comments
 (0)