From 213db47f6497c0ea49ffef19de0d4673c932eefd Mon Sep 17 00:00:00 2001 From: Deepa Dinamani Date: Tue, 1 Aug 2017 14:53:08 -0400 Subject: [PATCH] LU-9558 kernel: replace CURRENT_TIME macro CURRENT_TIME macro is not y2038 safe on 32 bit systems. The patch replaces all the uses of CURRENT_TIME by current_time() for filesystem times, and ktime_get_* functions for others. struct timespec is also not y2038 safe. Retain timespec for timestamp representation here as lustre uses it internally everywhere. These references will be changed to use struct timespec64 in a separate patch. This is also in preparation for the patch that transitions vfs timestamps to use 64 bit time and hence make them y2038 safe. current_time() is also planned to be transitioned to y2038 safe behavior along with this change. CURRENT_TIME macro will be deleted before merging the aforementioned change. Linux-commit: 47f38c539e9a42344ff5a664942075bd4df93876 Change-Id: Iec67df8f48066801c227aba2bc9221d444dada65 Link: http://lkml.kernel.org/r/1491613030-11599-10-git-send-email-deepa.kernel@gmail.com Signed-off-by: Deepa Dinamani Reviewed-on: https://review.whamcloud.com/28305 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: John L. Hammond Reviewed-by: Dmitry Eremin Reviewed-by: Oleg Drokin --- lustre/autoconf/lustre-core.m4 | 20 ++++++++++++++++++++ lustre/include/lustre_compat.h | 7 +++++++ lustre/llite/llite_lib.c | 6 +++--- lustre/osc/osc_io.c | 4 ++-- 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/lustre/autoconf/lustre-core.m4 b/lustre/autoconf/lustre-core.m4 index ffced12..d0c5ed0 100644 --- a/lustre/autoconf/lustre-core.m4 +++ b/lustre/autoconf/lustre-core.m4 @@ -2599,6 +2599,23 @@ vm_operations_no_vm_area_struct, [ ]) # LC_VM_OPERATIONS_REMOVE_VMF_ARG # +# Kernel version 4.12 commit 47f38c539e9a42344ff5a664942075bd4df93876 +# CURRENT_TIME is not 64 bit time safe so it was replaced with +# current_time() +# +AC_DEFUN([LC_CURRENT_TIME], [ +LB_CHECK_COMPILE([if CURRENT_TIME has been replaced with current_time], +current_time, [ + #include +],[ + struct timespec ts = current_time(NULL); +],[ + AC_DEFINE(HAVE_CURRENT_TIME, 1, + [current_time() has replaced CURRENT_TIME]) +]) +]) # LIBCFS_CURRENT_TIME + +# # LC_PROG_LINUX # # Lustre linux kernel checks @@ -2814,6 +2831,9 @@ AC_DEFUN([LC_PROG_LINUX], [ LC_INODEOPS_ENHANCED_GETATTR LC_VM_OPERATIONS_REMOVE_VMF_ARG + # 4.12 + LC_CURRENT_TIME + # AS_IF([test "x$enable_server" != xno], [ LC_STACK_SIZE diff --git a/lustre/include/lustre_compat.h b/lustre/include/lustre_compat.h index 8e2a9c6..ef60f3e 100644 --- a/lustre/include/lustre_compat.h +++ b/lustre/include/lustre_compat.h @@ -620,4 +620,11 @@ static inline void __user *get_vmf_address(struct vm_fault *vmf) # define ll_filemap_fault(vma, vmf) filemap_fault(vma, vmf) #endif +#ifndef HAVE_CURRENT_TIME +static inline struct timespec current_time(struct inode *inode) +{ + return CURRENT_TIME; +} +#endif + #endif /* _LUSTRE_COMPAT_H */ diff --git a/lustre/llite/llite_lib.c b/lustre/llite/llite_lib.c index ba305aa..4acf584 100644 --- a/lustre/llite/llite_lib.c +++ b/lustre/llite/llite_lib.c @@ -1571,17 +1571,17 @@ int ll_setattr_raw(struct dentry *dentry, struct iattr *attr, bool hsm_import) /* We mark all of the fields "set" so MDS/OST does not re-set them */ if (!(attr->ia_valid & ATTR_CTIME_SET) && (attr->ia_valid & ATTR_CTIME)) { - attr->ia_ctime = CURRENT_TIME; + attr->ia_ctime = current_time(inode); attr->ia_valid |= ATTR_CTIME_SET; } if (!(attr->ia_valid & ATTR_ATIME_SET) && (attr->ia_valid & ATTR_ATIME)) { - attr->ia_atime = CURRENT_TIME; + attr->ia_atime = current_time(inode); attr->ia_valid |= ATTR_ATIME_SET; } if (!(attr->ia_valid & ATTR_MTIME_SET) && (attr->ia_valid & ATTR_MTIME)) { - attr->ia_mtime = CURRENT_TIME; + attr->ia_mtime = current_time(inode); attr->ia_valid |= ATTR_MTIME_SET; } diff --git a/lustre/osc/osc_io.c b/lustre/osc/osc_io.c index b196fc8..65c511c 100644 --- a/lustre/osc/osc_io.c +++ b/lustre/osc/osc_io.c @@ -203,7 +203,7 @@ static int osc_io_submit(const struct lu_env *env, struct cl_attr *attr = &osc_env_info(env)->oti_attr; cl_object_attr_lock(obj); - attr->cat_mtime = attr->cat_ctime = LTIME_S(CURRENT_TIME); + attr->cat_mtime = attr->cat_ctime = ktime_get_real_seconds(); cl_object_attr_update(env, obj, attr, CAT_MTIME | CAT_CTIME); cl_object_attr_unlock(obj); } @@ -242,7 +242,7 @@ static void osc_page_touch_at(const struct lu_env *env, kms > loi->loi_kms ? "" : "not ", loi->loi_kms, kms, loi->loi_lvb.lvb_size); - attr->cat_mtime = attr->cat_ctime = LTIME_S(CURRENT_TIME); + attr->cat_mtime = attr->cat_ctime = ktime_get_real_seconds(); valid = CAT_MTIME | CAT_CTIME; if (kms > loi->loi_kms) { attr->cat_kms = kms; -- 1.8.3.1