Skip to content

Commit

Permalink
Linux 5.6 compat: timestamp_truncate()
Browse files Browse the repository at this point in the history
The timestamp_truncate() function was added, it replaces the existing
timespec64_trunc() function.  This change renames our wrapper function
to be consistent with the upstream name and updates the compatibility
code for older kernels accordingly.

Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #9956
Closes #9961
  • Loading branch information
behlendorf committed Feb 7, 2020
1 parent 0dd7364 commit 795699a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 18 deletions.
31 changes: 27 additions & 4 deletions config/kernel-inode-times.m4
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
dnl #
dnl # 4.18 API change
dnl # i_atime, i_mtime, and i_ctime changed from timespec to timespec64.
dnl #
AC_DEFUN([ZFS_AC_KERNEL_SRC_INODE_TIMES], [
dnl #
dnl # 5.6 API change
dnl # timespec64_trunc() replaced by timestamp_truncate() interface.
dnl #
ZFS_LINUX_TEST_SRC([timestamp_truncate], [
#include <linux/fs.h>
],[
struct timespec64 ts;
struct inode ip;
ts = timestamp_truncate(ts, &ip);
])
dnl #
dnl # 4.18 API change
dnl # i_atime, i_mtime, and i_ctime changed from timespec to timespec64.
dnl #
ZFS_LINUX_TEST_SRC([inode_times], [
#include <linux/fs.h>
],[
Expand All @@ -15,6 +29,15 @@ AC_DEFUN([ZFS_AC_KERNEL_SRC_INODE_TIMES], [
])

AC_DEFUN([ZFS_AC_KERNEL_INODE_TIMES], [
AC_MSG_CHECKING([whether timestamp_truncate() exists])
ZFS_LINUX_TEST_RESULT([timestamp_truncate], [
AC_MSG_RESULT(yes)
AC_DEFINE(HAVE_INODE_TIMESTAMP_TRUNCATE, 1,
[timestamp_truncate() exists])
],[
AC_MSG_RESULT(no)
])
AC_MSG_CHECKING([whether inode->i_*time's are timespec64])
ZFS_LINUX_TEST_RESULT([inode_times], [
AC_MSG_RESULT(no)
Expand Down
13 changes: 7 additions & 6 deletions include/os/linux/zfs/sys/zpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,14 @@ zpl_dir_emit_dots(struct file *file, zpl_dir_context_t *ctx)
}
#endif /* HAVE_VFS_ITERATE */

/*
* Linux 4.18, inode times converted from timespec to timespec64.
*/
#if defined(HAVE_INODE_TIMESPEC64_TIMES)
#define zpl_inode_timespec_trunc(ts, gran) timespec64_trunc(ts, gran)
#if defined(HAVE_INODE_TIMESTAMP_TRUNCATE)
#define zpl_inode_timestamp_truncate(ts, ip) timestamp_truncate(ts, ip)
#elif defined(HAVE_INODE_TIMESPEC64_TIMES)
#define zpl_inode_timestamp_truncate(ts, ip) \
timespec64_trunc(ts, (ip)->i_sb->s_time_gran)
#else
#define zpl_inode_timespec_trunc(ts, gran) timespec_trunc(ts, gran)
#define zpl_inode_timestamp_truncate(ts, ip) \
timespec_trunc(ts, (ip)->i_sb->s_time_gran)
#endif

#endif /* _SYS_ZPL_H */
8 changes: 4 additions & 4 deletions module/os/linux/zfs/zfs_vnops.c
Original file line number Diff line number Diff line change
Expand Up @@ -3444,17 +3444,17 @@ zfs_setattr(znode_t *zp, vattr_t *vap, int flags, cred_t *cr)

if (mask & (ATTR_MTIME | ATTR_SIZE)) {
ZFS_TIME_ENCODE(&vap->va_mtime, mtime);
ZTOI(zp)->i_mtime = zpl_inode_timespec_trunc(vap->va_mtime,
ZTOI(zp)->i_sb->s_time_gran);
ZTOI(zp)->i_mtime = zpl_inode_timestamp_truncate(
vap->va_mtime, ZTOI(zp));

SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MTIME(zfsvfs), NULL,
mtime, sizeof (mtime));
}

if (mask & (ATTR_CTIME | ATTR_SIZE)) {
ZFS_TIME_ENCODE(&vap->va_ctime, ctime);
ZTOI(zp)->i_ctime = zpl_inode_timespec_trunc(vap->va_ctime,
ZTOI(zp)->i_sb->s_time_gran);
ZTOI(zp)->i_ctime = zpl_inode_timestamp_truncate(vap->va_ctime,
ZTOI(zp));
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zfsvfs), NULL,
ctime, sizeof (ctime));
}
Expand Down
6 changes: 2 additions & 4 deletions module/os/linux/zfs/zpl_inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,8 @@ zpl_setattr(struct dentry *dentry, struct iattr *ia)
vap->va_mtime = ia->ia_mtime;
vap->va_ctime = ia->ia_ctime;

if (vap->va_mask & ATTR_ATIME) {
ip->i_atime = zpl_inode_timespec_trunc(ia->ia_atime,
ip->i_sb->s_time_gran);
}
if (vap->va_mask & ATTR_ATIME)
ip->i_atime = zpl_inode_timestamp_truncate(ia->ia_atime, ip);

cookie = spl_fstrans_mark();
error = -zfs_setattr(ITOZ(ip), vap, 0, cr);
Expand Down

1 comment on commit 795699a

@h1z1
Copy link

@h1z1 h1z1 commented on 795699a Feb 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@behlendorf Kinda related, any reason these aren't signed by your pgp key? :)

Please sign in to comment.