fs/ufs: use ktime_get_real_seconds for sb and cg timestamps

get_seconds() is deprecated because of the 32-bit overflow and will be
removed.  All callers in ufs also truncate to a 32-bit number, so
nothing changes during the conversion, but this should be harmless as
the superblock and cylinder group timestamps are not visible to user
space, except for checking the fs-dirty state, wich works fine across
the overflow.

This moves the call to get_seconds() into a new inline function, with a
comment explaining the constraints, while converting it to
ktime_get_real_seconds().

Link: http://lkml.kernel.org/r/20180718115017.742609-1-arnd@arndb.de
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Arnd Bergmann 2018-08-17 15:43:47 -07:00 committed by Linus Torvalds
parent 2c1bb29aa6
commit a3fda0ffea
4 changed files with 19 additions and 5 deletions

View File

@ -547,7 +547,7 @@ static u64 ufs_add_fragments(struct inode *inode, u64 fragment,
/* /*
* Block can be extended * Block can be extended
*/ */
ucg->cg_time = cpu_to_fs32(sb, get_seconds()); ucg->cg_time = ufs_get_seconds(sb);
for (i = newcount; i < (uspi->s_fpb - fragoff); i++) for (i = newcount; i < (uspi->s_fpb - fragoff); i++)
if (ubh_isclr (UCPI_UBH(ucpi), ucpi->c_freeoff, fragno + i)) if (ubh_isclr (UCPI_UBH(ucpi), ucpi->c_freeoff, fragno + i))
break; break;
@ -639,7 +639,7 @@ cg_found:
if (!ufs_cg_chkmagic(sb, ucg)) if (!ufs_cg_chkmagic(sb, ucg))
ufs_panic (sb, "ufs_alloc_fragments", ufs_panic (sb, "ufs_alloc_fragments",
"internal error, bad magic number on cg %u", cgno); "internal error, bad magic number on cg %u", cgno);
ucg->cg_time = cpu_to_fs32(sb, get_seconds()); ucg->cg_time = ufs_get_seconds(sb);
if (count == uspi->s_fpb) { if (count == uspi->s_fpb) {
result = ufs_alloccg_block (inode, ucpi, goal, err); result = ufs_alloccg_block (inode, ucpi, goal, err);

View File

@ -89,7 +89,7 @@ void ufs_free_inode (struct inode * inode)
if (!ufs_cg_chkmagic(sb, ucg)) if (!ufs_cg_chkmagic(sb, ucg))
ufs_panic (sb, "ufs_free_fragments", "internal error, bad cg magic number"); ufs_panic (sb, "ufs_free_fragments", "internal error, bad cg magic number");
ucg->cg_time = cpu_to_fs32(sb, get_seconds()); ucg->cg_time = ufs_get_seconds(sb);
is_directory = S_ISDIR(inode->i_mode); is_directory = S_ISDIR(inode->i_mode);

View File

@ -698,7 +698,7 @@ static int ufs_sync_fs(struct super_block *sb, int wait)
usb1 = ubh_get_usb_first(uspi); usb1 = ubh_get_usb_first(uspi);
usb3 = ubh_get_usb_third(uspi); usb3 = ubh_get_usb_third(uspi);
usb1->fs_time = cpu_to_fs32(sb, get_seconds()); usb1->fs_time = ufs_get_seconds(sb);
if ((flags & UFS_ST_MASK) == UFS_ST_SUN || if ((flags & UFS_ST_MASK) == UFS_ST_SUN ||
(flags & UFS_ST_MASK) == UFS_ST_SUNOS || (flags & UFS_ST_MASK) == UFS_ST_SUNOS ||
(flags & UFS_ST_MASK) == UFS_ST_SUNx86) (flags & UFS_ST_MASK) == UFS_ST_SUNx86)
@ -1342,7 +1342,7 @@ static int ufs_remount (struct super_block *sb, int *mount_flags, char *data)
*/ */
if (*mount_flags & SB_RDONLY) { if (*mount_flags & SB_RDONLY) {
ufs_put_super_internal(sb); ufs_put_super_internal(sb);
usb1->fs_time = cpu_to_fs32(sb, get_seconds()); usb1->fs_time = ufs_get_seconds(sb);
if ((flags & UFS_ST_MASK) == UFS_ST_SUN if ((flags & UFS_ST_MASK) == UFS_ST_SUN
|| (flags & UFS_ST_MASK) == UFS_ST_SUNOS || (flags & UFS_ST_MASK) == UFS_ST_SUNOS
|| (flags & UFS_ST_MASK) == UFS_ST_SUNx86) || (flags & UFS_ST_MASK) == UFS_ST_SUNx86)

View File

@ -590,3 +590,17 @@ static inline int ufs_is_data_ptr_zero(struct ufs_sb_private_info *uspi,
else else
return *(__fs32 *)p == 0; return *(__fs32 *)p == 0;
} }
static inline __fs32 ufs_get_seconds(struct super_block *sbp)
{
time64_t now = ktime_get_real_seconds();
/* Signed 32-bit interpretation wraps around in 2038, which
* happens in ufs1 inode stamps but not ufs2 using 64-bits
* stamps. For superblock and blockgroup, let's assume
* unsigned 32-bit stamps, which are good until y2106.
* Wrap around rather than clamp here to make the dirty
* file system detection work in the superblock stamp.
*/
return cpu_to_fs32(sbp, lower_32_bits(now));
}