From 3af55b3159ac2133dc35eeb2f02825848fb65548 Mon Sep 17 00:00:00 2001 From: Li Dongyang Date: Tue, 16 Apr 2019 11:14:13 +1000 Subject: [PATCH] LU-11838 osd-ldiskfs: inode times switched to timespec64 Since kernel 4.18 inode times swtich from struct timespec to timespec64 to make it y2038 safe. Linux-commit: 95582b00838837fc07e042979320caf917ce3fe6 Test-Parameters:trivial Signed-off-by: Li Dongyang Change-Id: Iaddb2f2be27ec348fb97e13371aa3d7e6f6e5c9f Reviewed-on: https://review.whamcloud.com/34675 Reviewed-by: Gu Zheng Reviewed-by: Andreas Dilger Reviewed-by: James Simmons Tested-by: Jenkins Tested-by: Maloo --- lustre/autoconf/lustre-core.m4 | 24 ++++++++++++++++++++++++ lustre/osd-ldiskfs/osd_handler.c | 19 ++++++++++++++----- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/lustre/autoconf/lustre-core.m4 b/lustre/autoconf/lustre-core.m4 index 45271d6..cf9a753 100644 --- a/lustre/autoconf/lustre-core.m4 +++ b/lustre/autoconf/lustre-core.m4 @@ -3078,6 +3078,27 @@ i_pages, [ ]) # LC_I_PAGES # +# LC_INODE_TIMESPEC64 +# +# kernel 4.18 commit 95582b00838837fc07e042979320caf917ce3fe6 +# inode timestamps switched to timespec64 +# +AC_DEFUN([LC_INODE_TIMESPEC64], [ +LB_CHECK_COMPILE([if inode timestamps are struct timespec64], +inode_timespec64, [ + #include +],[ + struct inode inode = {}; + struct timespec64 ts = {}; + + inode.i_atime = ts; +],[ + AC_DEFINE(HAVE_INODE_TIMESPEC64, 1, + [inode times are using timespec64]) +]) +]) # LC_INODE_TIMESPEC64 + +# # LC_PROG_LINUX # # Lustre linux kernel checks @@ -3325,6 +3346,9 @@ AC_DEFUN([LC_PROG_LINUX], [ # 4.17 LC_I_PAGES + # 4.18 + LC_INODE_TIMESPEC64 + # kernel patch to extend integrity interface LC_BIO_INTEGRITY_PREP_FN diff --git a/lustre/osd-ldiskfs/osd_handler.c b/lustre/osd-ldiskfs/osd_handler.c index cf8b64d..edf9dbb 100644 --- a/lustre/osd-ldiskfs/osd_handler.c +++ b/lustre/osd-ldiskfs/osd_handler.c @@ -2602,8 +2602,13 @@ static int osd_write_locked(const struct lu_env *env, struct dt_object *dt) return obj->oo_owner == env; } -static struct timespec *osd_inode_time(const struct lu_env *env, +#ifdef HAVE_INODE_TIMESPEC64 +static struct timespec64 osd_inode_time(const struct lu_env *env, struct inode *inode, __u64 seconds) +#else +static struct timespec osd_inode_time(const struct lu_env *env, + struct inode *inode, __u64 seconds) +#endif { struct osd_thread_info *oti = osd_oti_get(env); struct timespec *t = &oti->oti_time; @@ -2611,7 +2616,11 @@ static struct timespec *osd_inode_time(const struct lu_env *env, t->tv_sec = seconds; t->tv_nsec = 0; *t = timespec_trunc(*t, inode->i_sb->s_time_gran); - return t; +#ifdef HAVE_INODE_TIMESPEC64 + return timespec_to_timespec64(*t); +#else + return *t; +#endif } static void osd_inode_getattr(const struct lu_env *env, @@ -2829,11 +2838,11 @@ static int osd_inode_setattr(const struct lu_env *env, return 0; if (bits & LA_ATIME) - inode->i_atime = *osd_inode_time(env, inode, attr->la_atime); + inode->i_atime = osd_inode_time(env, inode, attr->la_atime); if (bits & LA_CTIME) - inode->i_ctime = *osd_inode_time(env, inode, attr->la_ctime); + inode->i_ctime = osd_inode_time(env, inode, attr->la_ctime); if (bits & LA_MTIME) - inode->i_mtime = *osd_inode_time(env, inode, attr->la_mtime); + inode->i_mtime = osd_inode_time(env, inode, attr->la_mtime); if (bits & LA_SIZE) { spin_lock(&inode->i_lock); LDISKFS_I(inode)->i_disksize = attr->la_size; -- 1.8.3.1