]>
Commit | Line | Data |
---|---|---|
f0371a1b SI |
1 | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
2 | From: Brian Behlendorf <behlendorf1@llnl.gov> | |
3 | Date: Sun, 12 Aug 2018 18:22:54 -0400 | |
4 | Subject: [PATCH] Linux 4.18 compat: inode timespec -> timespec64 | |
5 | ||
6 | Commit torvalds/linux@95582b0 changes the inode i_atime, i_mtime, | |
7 | and i_ctime members form timespec's to timespec64's to make them | |
8 | 2038 safe. As part of this change the current_time() function was | |
9 | also updated to return the timespec64 type. | |
10 | ||
11 | Resolve this issue by introducing a new inode_timespec_t type which | |
12 | is defined to match the timespec type used by the inode. It should | |
13 | be used when working with inode timestamps to ensure matching types. | |
14 | ||
15 | The timestruc_t type under Illumos was used in a similar fashion but | |
16 | was specified to always be a timespec_t. Rather than incorrectly | |
17 | define this type all timespec_t types have been replaced by the new | |
18 | inode_timespec_t type. | |
19 | ||
20 | Finally, the kernel and user space 'sys/time.h' headers were aligned | |
21 | with each other. They define as appropriate for the context several | |
22 | constants as macros and include static inline implementation of | |
23 | gethrestime(), gethrestime_sec(), and gethrtime(). | |
24 | ||
25 | Reviewed-by: Chunwei Chen <tuxoko@gmail.com> | |
26 | Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> | |
27 | Closes #7643 | |
28 | Backported-by: Richard Yao <ryao@gentoo.org> | |
29 | ||
30 | Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com> | |
31 | --- | |
32 | config/kernel-inode-times.m4 | 25 +++++++++++++++++++++++++ | |
33 | config/spl-build.m4 | 1 + | |
34 | include/sys/condvar.h | 1 + | |
35 | include/sys/time.h | 25 +++++++++++++++++++------ | |
36 | include/sys/types.h | 3 --- | |
37 | include/sys/vnode.h | 6 +++--- | |
38 | 6 files changed, 49 insertions(+), 12 deletions(-) | |
39 | create mode 100644 config/kernel-inode-times.m4 | |
40 | ||
41 | diff --git a/config/kernel-inode-times.m4 b/config/kernel-inode-times.m4 | |
42 | new file mode 100644 | |
43 | index 0000000..3a6acd8 | |
44 | --- /dev/null | |
45 | +++ b/config/kernel-inode-times.m4 | |
46 | @@ -0,0 +1,25 @@ | |
47 | +dnl # | |
48 | +dnl # 4.18 API change | |
49 | +dnl # i_atime, i_mtime, and i_ctime changed from timespec to timespec64. | |
50 | +dnl # | |
51 | +AC_DEFUN([SPL_AC_KERNEL_INODE_TIMES], [ | |
52 | + AC_MSG_CHECKING([whether inode->i_*time's are timespec64]) | |
53 | + tmp_flags="$EXTRA_KCFLAGS" | |
54 | + EXTRA_KCFLAGS="-Werror" | |
55 | + SPL_LINUX_TRY_COMPILE([ | |
56 | + #include <linux/fs.h> | |
57 | + ],[ | |
58 | + struct inode ip; | |
59 | + struct timespec ts; | |
60 | + | |
61 | + memset(&ip, 0, sizeof(ip)); | |
62 | + ts = ip.i_mtime; | |
63 | + ],[ | |
64 | + AC_MSG_RESULT(no) | |
65 | + ],[ | |
66 | + AC_MSG_RESULT(yes) | |
67 | + AC_DEFINE(HAVE_INODE_TIMESPEC64_TIMES, 1, | |
68 | + [inode->i_*time's are timespec64]) | |
69 | + ]) | |
70 | + EXTRA_KCFLAGS="$tmp_flags" | |
71 | +]) | |
72 | diff --git a/config/spl-build.m4 b/config/spl-build.m4 | |
73 | index 5c6c02a..0dc5be8 100644 | |
74 | --- a/config/spl-build.m4 | |
75 | +++ b/config/spl-build.m4 | |
76 | @@ -43,6 +43,7 @@ AC_DEFUN([SPL_AC_CONFIG_KERNEL], [ | |
77 | SPL_AC_2ARGS_VFS_GETATTR | |
78 | SPL_AC_USLEEP_RANGE | |
79 | SPL_AC_KMEM_CACHE_ALLOCFLAGS | |
80 | + SPL_AC_KERNEL_INODE_TIMES | |
81 | SPL_AC_WAIT_ON_BIT | |
82 | SPL_AC_INODE_LOCK | |
83 | SPL_AC_GROUP_INFO_GID | |
84 | diff --git a/include/sys/condvar.h b/include/sys/condvar.h | |
85 | index 5fcc906..ce3149a 100644 | |
86 | --- a/include/sys/condvar.h | |
87 | +++ b/include/sys/condvar.h | |
88 | @@ -31,6 +31,7 @@ | |
89 | #include <sys/kmem.h> | |
90 | #include <sys/mutex.h> | |
91 | #include <sys/callo.h> | |
92 | +#include <sys/time.h> | |
93 | ||
94 | /* | |
95 | * The kcondvar_t struct is protected by mutex taken externally before | |
96 | diff --git a/include/sys/time.h b/include/sys/time.h | |
97 | index ddda6de..59557af 100644 | |
98 | --- a/include/sys/time.h | |
99 | +++ b/include/sys/time.h | |
100 | @@ -52,15 +52,28 @@ | |
101 | #define NSEC2SEC(n) ((n) / (NANOSEC / SEC)) | |
102 | #define SEC2NSEC(m) ((hrtime_t)(m) * (NANOSEC / SEC)) | |
103 | ||
104 | +typedef longlong_t hrtime_t; | |
105 | +typedef struct timespec timespec_t; | |
106 | + | |
107 | static const int hz = HZ; | |
108 | ||
109 | #define TIMESPEC_OVERFLOW(ts) \ | |
110 | ((ts)->tv_sec < TIME_MIN || (ts)->tv_sec > TIME_MAX) | |
111 | ||
112 | +#if defined(HAVE_INODE_TIMESPEC64_TIMES) | |
113 | +typedef struct timespec64 inode_timespec_t; | |
114 | +#else | |
115 | +typedef struct timespec inode_timespec_t; | |
116 | +#endif | |
117 | + | |
118 | static inline void | |
119 | -gethrestime(timestruc_t *now) | |
120 | -{ | |
121 | - *now = current_kernel_time(); | |
122 | +gethrestime(inode_timespec_t *ts) | |
123 | + { | |
124 | +#if defined(HAVE_INODE_TIMESPEC64_TIMES) | |
125 | + *ts = current_kernel_time64(); | |
126 | +#else | |
127 | + *ts = current_kernel_time(); | |
128 | +#endif | |
129 | } | |
130 | ||
131 | static inline time_t | |
132 | @@ -74,9 +87,9 @@ gethrestime_sec(void) | |
133 | static inline hrtime_t | |
134 | gethrtime(void) | |
135 | { | |
136 | - struct timespec now; | |
137 | - getrawmonotonic(&now); | |
138 | - return (((hrtime_t)now.tv_sec * NSEC_PER_SEC) + now.tv_nsec); | |
139 | + struct timespec ts; | |
140 | + getrawmonotonic(&ts); | |
141 | + return (((hrtime_t)ts.tv_sec * NSEC_PER_SEC) + ts.tv_nsec); | |
142 | } | |
143 | ||
144 | #endif /* _SPL_TIME_H */ | |
145 | diff --git a/include/sys/types.h b/include/sys/types.h | |
146 | index 2fe63b7..b958462 100644 | |
147 | --- a/include/sys/types.h | |
148 | +++ b/include/sys/types.h | |
149 | @@ -49,9 +49,6 @@ typedef long long offset_t; | |
150 | typedef struct task_struct kthread_t; | |
151 | typedef struct task_struct proc_t; | |
152 | typedef short pri_t; | |
153 | -typedef struct timespec timestruc_t; /* definition per SVr4 */ | |
154 | -typedef struct timespec timespec_t; | |
155 | -typedef longlong_t hrtime_t; | |
156 | typedef unsigned short ushort_t; | |
157 | typedef u_longlong_t len_t; | |
158 | typedef longlong_t diskaddr_t; | |
159 | diff --git a/include/sys/vnode.h b/include/sys/vnode.h | |
160 | index 0ed4794..87f12d6 100644 | |
161 | --- a/include/sys/vnode.h | |
162 | +++ b/include/sys/vnode.h | |
163 | @@ -129,9 +129,9 @@ typedef struct vattr { | |
164 | long va_nodeid; /* node # */ | |
165 | uint32_t va_nlink; /* # links */ | |
166 | uint64_t va_size; /* file size */ | |
167 | - struct timespec va_atime; /* last acc */ | |
168 | - struct timespec va_mtime; /* last mod */ | |
169 | - struct timespec va_ctime; /* last chg */ | |
170 | + inode_timespec_t va_atime; /* last acc */ | |
171 | + inode_timespec_t va_mtime; /* last mod */ | |
172 | + inode_timespec_t va_ctime; /* last chg */ | |
173 | dev_t va_rdev; /* dev */ | |
174 | uint64_t va_nblocks; /* space used */ | |
175 | uint32_t va_blksize; /* block size */ | |
176 | -- | |
177 | 2.11.0 | |
178 |