Skip to content

Commit 3a3d1e5

Browse files
arndbtorvalds
authored andcommitted
ocfs2: dlmglue: clean up timestamp handling
The handling of timestamps outside of the 1970..2038 range in the dlm glue is rather inconsistent: on 32-bit architectures, this has always wrapped around to negative timestamps in the 1902..1969 range, while on 64-bit kernels all timestamps are interpreted as positive 34 bit numbers in the 1970..2514 year range. Now that the VFS code handles 64-bit timestamps on all architectures, we can make the behavior more consistent here, and return the same result that we had on 64-bit already, making the file system y2038 safe in the process. Outside of dlmglue, it already uses 64-bit on-disk timestamps anway, so that part is fine. For consistency, I'm changing ocfs2_pack_timespec() to clamp anything outside of the supported range to the minimum and maximum values. This avoids a possible ambiguity of values before 1970 in particular, which used to be interpreted as times at the end of the 2514 range previously. Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnd Bergmann <[email protected]> Reviewed-by: Andrew Morton <[email protected]> Cc: Mark Fasheh <[email protected]> Cc: Joel Becker <[email protected]> Cc: Junxiao Bi <[email protected]> Cc: Joseph Qi <[email protected]> Cc: Changwei Ge <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent cf76c78 commit 3a3d1e5

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

fs/ocfs2/dlmglue.c

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2123,10 +2123,10 @@ static void ocfs2_downconvert_on_unlock(struct ocfs2_super *osb,
21232123

21242124
/* LVB only has room for 64 bits of time here so we pack it for
21252125
* now. */
2126-
static u64 ocfs2_pack_timespec(struct timespec *spec)
2126+
static u64 ocfs2_pack_timespec(struct timespec64 *spec)
21272127
{
21282128
u64 res;
2129-
u64 sec = spec->tv_sec;
2129+
u64 sec = clamp_t(time64_t, spec->tv_sec, 0, 0x3ffffffffull);
21302130
u32 nsec = spec->tv_nsec;
21312131

21322132
res = (sec << OCFS2_SEC_SHIFT) | (nsec & OCFS2_NSEC_MASK);
@@ -2142,7 +2142,6 @@ static void __ocfs2_stuff_meta_lvb(struct inode *inode)
21422142
struct ocfs2_inode_info *oi = OCFS2_I(inode);
21432143
struct ocfs2_lock_res *lockres = &oi->ip_inode_lockres;
21442144
struct ocfs2_meta_lvb *lvb;
2145-
struct timespec ts;
21462145

21472146
lvb = ocfs2_dlm_lvb(&lockres->l_lksb);
21482147

@@ -2163,15 +2162,12 @@ static void __ocfs2_stuff_meta_lvb(struct inode *inode)
21632162
lvb->lvb_igid = cpu_to_be32(i_gid_read(inode));
21642163
lvb->lvb_imode = cpu_to_be16(inode->i_mode);
21652164
lvb->lvb_inlink = cpu_to_be16(inode->i_nlink);
2166-
ts = timespec64_to_timespec(inode->i_atime);
21672165
lvb->lvb_iatime_packed =
2168-
cpu_to_be64(ocfs2_pack_timespec(&ts));
2169-
ts = timespec64_to_timespec(inode->i_ctime);
2166+
cpu_to_be64(ocfs2_pack_timespec(&inode->i_atime));
21702167
lvb->lvb_ictime_packed =
2171-
cpu_to_be64(ocfs2_pack_timespec(&ts));
2172-
ts = timespec64_to_timespec(inode->i_mtime);
2168+
cpu_to_be64(ocfs2_pack_timespec(&inode->i_ctime));
21732169
lvb->lvb_imtime_packed =
2174-
cpu_to_be64(ocfs2_pack_timespec(&ts));
2170+
cpu_to_be64(ocfs2_pack_timespec(&inode->i_mtime));
21752171
lvb->lvb_iattr = cpu_to_be32(oi->ip_attr);
21762172
lvb->lvb_idynfeatures = cpu_to_be16(oi->ip_dyn_features);
21772173
lvb->lvb_igeneration = cpu_to_be32(inode->i_generation);
@@ -2180,7 +2176,7 @@ static void __ocfs2_stuff_meta_lvb(struct inode *inode)
21802176
mlog_meta_lvb(0, lockres);
21812177
}
21822178

2183-
static void ocfs2_unpack_timespec(struct timespec *spec,
2179+
static void ocfs2_unpack_timespec(struct timespec64 *spec,
21842180
u64 packed_time)
21852181
{
21862182
spec->tv_sec = packed_time >> OCFS2_SEC_SHIFT;
@@ -2189,7 +2185,6 @@ static void ocfs2_unpack_timespec(struct timespec *spec,
21892185

21902186
static void ocfs2_refresh_inode_from_lvb(struct inode *inode)
21912187
{
2192-
struct timespec ts;
21932188
struct ocfs2_inode_info *oi = OCFS2_I(inode);
21942189
struct ocfs2_lock_res *lockres = &oi->ip_inode_lockres;
21952190
struct ocfs2_meta_lvb *lvb;
@@ -2217,15 +2212,12 @@ static void ocfs2_refresh_inode_from_lvb(struct inode *inode)
22172212
i_gid_write(inode, be32_to_cpu(lvb->lvb_igid));
22182213
inode->i_mode = be16_to_cpu(lvb->lvb_imode);
22192214
set_nlink(inode, be16_to_cpu(lvb->lvb_inlink));
2220-
ocfs2_unpack_timespec(&ts,
2215+
ocfs2_unpack_timespec(&inode->i_atime,
22212216
be64_to_cpu(lvb->lvb_iatime_packed));
2222-
inode->i_atime = timespec_to_timespec64(ts);
2223-
ocfs2_unpack_timespec(&ts,
2217+
ocfs2_unpack_timespec(&inode->i_mtime,
22242218
be64_to_cpu(lvb->lvb_imtime_packed));
2225-
inode->i_mtime = timespec_to_timespec64(ts);
2226-
ocfs2_unpack_timespec(&ts,
2219+
ocfs2_unpack_timespec(&inode->i_ctime,
22272220
be64_to_cpu(lvb->lvb_ictime_packed));
2228-
inode->i_ctime = timespec_to_timespec64(ts);
22292221
spin_unlock(&oi->ip_lock);
22302222
}
22312223

0 commit comments

Comments
 (0)