Whamcloud - gitweb
LU-9558 kernel: replace CURRENT_TIME macro 05/28305/2
authorDeepa Dinamani <deepa.kernel@gmail.com>
Tue, 1 Aug 2017 18:53:08 +0000 (14:53 -0400)
committerOleg Drokin <oleg.drokin@intel.com>
Wed, 9 Aug 2017 04:18:40 +0000 (04:18 +0000)
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 <deepa.kernel@gmail.com>
Reviewed-on: https://review.whamcloud.com/28305
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: John L. Hammond <john.hammond@intel.com>
Reviewed-by: Dmitry Eremin <dmitry.eremin@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/autoconf/lustre-core.m4
lustre/include/lustre_compat.h
lustre/llite/llite_lib.c
lustre/osc/osc_io.c

index ffced12..d0c5ed0 100644 (file)
@@ -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 <linux/fs.h>
+],[
+       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
index 8e2a9c6..ef60f3e 100644 (file)
@@ -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 */
index ba305aa..4acf584 100644 (file)
@@ -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;
         }
 
index b196fc8..65c511c 100644 (file)
@@ -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;