From b91d292473a786439e5f384121b81354cfe487f4 Mon Sep 17 00:00:00 2001 From: Li Dongyang Date: Mon, 17 Jun 2019 12:01:36 -0700 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 This patch is back-ported from the following one: Lustre-commit: 3af55b3159ac2133dc35eeb2f02825848fb65548 Lustre-change: https://review.whamcloud.com/34675 Test-Parameters:trivial Signed-off-by: Li Dongyang Change-Id: Iaddb2f2be27ec348fb97e13371aa3d7e6f6e5c9f Reviewed-by: Gu Zheng Reviewed-by: James Simmons Reviewed-on: https://review.whamcloud.com/35247 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Yang Sheng Reviewed-by: Oleg Drokin --- 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 9f736fb..866117b 100644 --- a/lustre/autoconf/lustre-core.m4 +++ b/lustre/autoconf/lustre-core.m4 @@ -3035,6 +3035,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 @@ -3280,6 +3301,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 56d04d8..2189a75 100644 --- a/lustre/osd-ldiskfs/osd_handler.c +++ b/lustre/osd-ldiskfs/osd_handler.c @@ -2598,8 +2598,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; @@ -2607,7 +2612,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, @@ -2825,11 +2834,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