Whamcloud - gitweb
LU-9558 kernel: replace CURRENT_TIME macro 72/30572/2
authorDeepa Dinamani <deepa.kernel@gmail.com>
Tue, 1 Aug 2017 18:53:08 +0000 (14:53 -0400)
committerJohn L. Hammond <john.hammond@intel.com>
Wed, 20 Dec 2017 17:44:27 +0000 (17:44 +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

Lustre-change: https://review.whamcloud.com/28305
Lustre-commit: 213db47f6497c0ea49ffef19de0d4673c932eefd

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-by: John L. Hammond <john.hammond@intel.com>
Reviewed-by: Dmitry Eremin <dmitry.eremin@intel.com>
Signed-off-by: Minh Diep <minh.diep@intel.com>
Reviewed-on: https://review.whamcloud.com/30572
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
lustre/autoconf/lustre-core.m4
lustre/include/lustre_compat.h
lustre/llite/llite_lib.c
lustre/osc/osc_io.c

index 18d0c7c..4b1e494 100644 (file)
@@ -2672,6 +2672,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
@@ -2891,6 +2908,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 cb9712d..237d7b8 100644 (file)
@@ -644,4 +644,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 40b57d9..93ea97e 100644 (file)
@@ -1576,17 +1576,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 0501ba5..38fe253 100644 (file)
@@ -216,7 +216,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);
        }
@@ -255,7 +255,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;