Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <deepa.kernel@gmail.com>
Acked-by: Jeff Layton <jlayton@kernel.org>

+32 -1
+32 -1
fs/namespace.c
··· 2463 2463 unlock_mount_hash(); 2464 2464 } 2465 2465 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 + 2466 2486 /* 2467 2487 * Handle reconfiguration of the mountpoint only without alteration of the 2468 2488 * superblock it refers to. This is triggered by specifying MS_REMOUNT|MS_BIND ··· 2508 2488 if (ret == 0) 2509 2489 set_mount_attributes(mnt, mnt_flags); 2510 2490 up_write(&sb->s_umount); 2491 + 2492 + mnt_warn_timestamp_expiry(path, &mnt->mnt); 2493 + 2511 2494 return ret; 2512 2495 } 2513 2496 ··· 2551 2528 } 2552 2529 up_write(&sb->s_umount); 2553 2530 } 2531 + 2532 + mnt_warn_timestamp_expiry(path, &mnt->mnt); 2533 + 2554 2534 put_fs_context(fc); 2555 2535 return err; 2556 2536 } ··· 2762 2736 return PTR_ERR(mnt); 2763 2737 2764 2738 error = do_add_mount(real_mount(mnt), mountpoint, mnt_flags); 2765 - if (error < 0) 2739 + if (error < 0) { 2766 2740 mntput(mnt); 2741 + return error; 2742 + } 2743 + 2744 + mnt_warn_timestamp_expiry(mountpoint, mnt); 2745 + 2767 2746 return error; 2768 2747 } 2769 2748