[Y2038] [PATCH 00/10] Remove CURRENT_TIME and CURRENT_TIME_SEC - PART 1
Introduction This patch series is aimed at getting rid of CURRENT_TIME and CURRENT_TIME_SEC macros. The idea for the series evolved from my discussions with Arnd Bergmann. This was originally part of the RFC series[2]: https://lkml.org/lkml/2016/1/7/20 (under discussion). Dave Chinner suggested moving bug fixes out of the feature series to keep the original series simple. There are 354 occurrences of the the above macros in the kernel. The series will be divided into 4 or 5 parts to keep the parts manageable and so that each part could be reviewed and merged independently. This is part 1 of the series. Motivation The macros: CURRENT_TIME and CURRENT_TIME_SEC are primarily used for filesystem timestamps. But, they are not accurate as they do not perform clamping according to filesystem timestamps ranges, nor do they truncate the nanoseconds value to the granularity as required by the filesystem. The series is also viewed as an ancillary to another upcoming series[2] that attempts to transition file system timestamps to use 64 bit time to make these y2038 safe. There will also be another series[3] to add range checks and clamping to filesystem time functions that are meant to substitute the above macros. Solution CURRENT_TIME macro has an equivalent function: struct timespec current_fs_time(struct super_block *sb) These will be the changes to the above function: 1. Function will return the type y2038 safe timespec64 in [2]. 2. Function will use y2038 safe 64 bit functions in [2]. 3. Function will be extended to perform range checks in [3]. A new function will be added to substitute for CURRENT_TIME_SEC macro in the current series: struct timespec current_fs_time_sec(void) These will be the changes to the above function: 1. Function will return the type y2038 safe timespec64 in [2]. 2. Function will use y2038 safe 64 bit functions in [2]. 3. Function will be extended to perform range checks in [3]. Any use of these macros outside of filesystem timestamps will be replaced by function calls to appropriate time functions. Deepa Dinamani (10): fs: Add current_fs_time_sec() function vfs: Replace CURRENT_TIME by current_fs_time() fs: cifs: Replace CURRENT_TIME with current_fs_time() fs: cifs: Replace CURRENT_TIME with ktime_get_real_ts() fs: cifs: Replace CURRENT_TIME by get_seconds fs: ext4: Replace CURRENT_TIME_SEC with current_fs_time_sec() fs: ext4: Replace CURRENT_TIME with ext4_current_time() fs: ceph: replace CURRENT_TIME by current_fs_time() fs: ceph: Replace CURRENT_TIME by ktime_get_real_ts() fs: btrfs: Replace CURRENT_TIME by current_fs_time() fs/btrfs/file.c| 4 ++-- fs/btrfs/inode.c | 25 + fs/btrfs/ioctl.c | 8 fs/btrfs/root-tree.c | 2 +- fs/btrfs/transaction.c | 7 +-- fs/btrfs/xattr.c | 2 +- fs/ceph/file.c | 4 ++-- fs/ceph/inode.c| 2 +- fs/ceph/mds_client.c | 2 +- fs/ceph/xattr.c| 4 ++-- fs/cifs/cifsencrypt.c | 4 +++- fs/cifs/cifssmb.c | 10 +- fs/cifs/inode.c| 15 +++ fs/ext4/ext4.h | 2 +- fs/ext4/super.c| 2 +- fs/libfs.c | 21 + fs/nsfs.c | 3 ++- fs/pipe.c | 3 ++- fs/posix_acl.c | 2 +- include/linux/fs.h | 5 + 20 files changed, 72 insertions(+), 55 deletions(-) -- 1.9.1 ___ Y2038 mailing list Y2038@lists.linaro.org https://lists.linaro.org/mailman/listinfo/y2038
[Y2038] [PATCH 01/10] fs: Add current_fs_time_sec() function
This is in preparation for the series that transitions filesystem timestamps to use 64 bit time and hence make them y2038 safe. The function is meant to replace CURRENT_TIME_SEC macro. The macro CURRENT_TIME_SEC does not represent filesystem times correctly as it cannot perform range checks. current_fs_time_sec() will be extended to include these. CURRENT_TIME_SEC is also not y2038 safe. current_fs_time_sec() will be transitioned to use 64 bit time along with vfs in a separate series. The function is inline for now to maintain similar performance to that of the macro. The function takes super block as a parameter to allow for future range checking of filesystem timestamps. Signed-off-by: Deepa DinamaniCc: Alexander Viro Cc: linux-fsde...@vger.kernel.org --- include/linux/fs.h | 5 + 1 file changed, 5 insertions(+) diff --git a/include/linux/fs.h b/include/linux/fs.h index 6a75571..4af612f 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1407,6 +1407,11 @@ struct super_block { extern struct timespec current_fs_time(struct super_block *sb); +static inline struct timespec current_fs_time_sec(struct super_block *sb) +{ + return (struct timespec) { get_seconds(), 0 }; +} + /* * Snapshotting support. */ -- 1.9.1 ___ Y2038 mailing list Y2038@lists.linaro.org https://lists.linaro.org/mailman/listinfo/y2038
[Y2038] [PATCH 04/10] fs: cifs: Replace CURRENT_TIME with ktime_get_real_ts()
This is in preparation for the series that transitions filesystem timestamps to use 64 bit time and hence make them y2038 safe. CURRENT_TIME macro will be deleted before merging the aforementioned series. Filesystem times will use current_fs_time() instead of CURRENT_TIME. Use ktime_get_real_ts() here as this is not filesystem time. ktime_get_real_ts() returns the timestamp in ns which can be used to calculate network time for NTLMv2 authentication timestamp. Signed-off-by: Deepa DinamaniCc: Steve French Cc: linux-c...@vger.kernel.org Cc: samba-techni...@lists.samba.org --- fs/cifs/cifsencrypt.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/cifs/cifsencrypt.c b/fs/cifs/cifsencrypt.c index d411654..f86e07d 100644 --- a/fs/cifs/cifsencrypt.c +++ b/fs/cifs/cifsencrypt.c @@ -460,6 +460,7 @@ find_timestamp(struct cifs_ses *ses) unsigned char *blobptr; unsigned char *blobend; struct ntlmssp2_name *attrptr; + struct timespec ts; if (!ses->auth_key.len || !ses->auth_key.response) return 0; @@ -484,7 +485,8 @@ find_timestamp(struct cifs_ses *ses) blobptr += attrsize; /* advance attr value */ } - return cpu_to_le64(cifs_UnixTimeToNT(CURRENT_TIME)); + ktime_get_real_ts(); + return cpu_to_le64(cifs_UnixTimeToNT(ts)); } static int calc_ntlmv2_hash(struct cifs_ses *ses, char *ntlmv2_hash, -- 1.9.1 ___ Y2038 mailing list Y2038@lists.linaro.org https://lists.linaro.org/mailman/listinfo/y2038
[Y2038] [PATCH 05/10] fs: cifs: Replace CURRENT_TIME by get_seconds
This is in preparation for the series that transitions filesystem timestamps to use 64 bit time and hence make them y2038 safe. CURRENT_TIME macro will be deleted before merging the aforementioned series. Filesystems will use current_fs_time() instead of CURRENT_TIME. Use get_seconds() here as this is not filesystem time. Only the seconds portion of the timestamp is necessary for timezone calculation using server time. Assume that the difference between server and client times lie in the range INT_MIN..INT_MAX. This is valid because this is the difference between current times between server and client, and the largest timezone difference is in the range of one day. Signed-off-by: Deepa DinamaniCc: Steve French Cc: linux-c...@vger.kernel.org Cc: samba-techni...@lists.samba.org --- fs/cifs/cifssmb.c | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c index 90b4f9f..1a9e43d 100644 --- a/fs/cifs/cifssmb.c +++ b/fs/cifs/cifssmb.c @@ -478,14 +478,14 @@ decode_lanman_negprot_rsp(struct TCP_Server_Info *server, NEGOTIATE_RSP *pSMBr) * this requirement. */ int val, seconds, remain, result; - struct timespec ts, utc; - utc = CURRENT_TIME; + struct timespec ts; + unsigned long utc = get_seconds(); ts = cnvrtDosUnixTm(rsp->SrvTime.Date, rsp->SrvTime.Time, 0); cifs_dbg(FYI, "SrvTime %d sec since 1970 (utc: %d) diff: %d\n", -(int)ts.tv_sec, (int)utc.tv_sec, -(int)(utc.tv_sec - ts.tv_sec)); - val = (int)(utc.tv_sec - ts.tv_sec); +(int)ts.tv_sec, (int)utc, +(int)(utc - ts.tv_sec)); + val = (int)(utc - ts.tv_sec); seconds = abs(val); result = (seconds / MIN_TZ_ADJ) * MIN_TZ_ADJ; remain = seconds % MIN_TZ_ADJ; -- 1.9.1 ___ Y2038 mailing list Y2038@lists.linaro.org https://lists.linaro.org/mailman/listinfo/y2038
[Y2038] [PATCH 07/10] fs: ext4: Replace CURRENT_TIME with ext4_current_time()
CURRENT_TIME macro is not appropriate for filesystems as it doesn't use the right granularity for filesystem timestamps. Use ext4_current_time() instead which is appropriate for ext4 timestamps. Signed-off-by: Deepa DinamaniCc: "Theodore Ts'o" Cc: Andreas Dilger Cc: linux-e...@vger.kernel.org --- fs/ext4/super.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 3ed01ec..5e6c866 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -5139,7 +5139,7 @@ static int ext4_quota_off(struct super_block *sb, int type) handle = ext4_journal_start(inode, EXT4_HT_QUOTA, 1); if (IS_ERR(handle)) goto out; - inode->i_mtime = inode->i_ctime = CURRENT_TIME; + inode->i_mtime = inode->i_ctime = ext4_current_time(inode); ext4_mark_inode_dirty(handle, inode); ext4_journal_stop(handle); -- 1.9.1 ___ Y2038 mailing list Y2038@lists.linaro.org https://lists.linaro.org/mailman/listinfo/y2038
[Y2038] [PATCH 10/10] fs: btrfs: Replace CURRENT_TIME by current_fs_time()
CURRENT_TIME macro is not appropriate for filesystems as it doesn't use the right granularity for filesystem timestamps. Use current_fs_time() instead. Signed-off-by: Deepa DinamaniCc: Chris Mason Cc: Josef Bacik Cc: David Sterba Cc: linux-bt...@vger.kernel.org --- fs/btrfs/file.c| 4 ++-- fs/btrfs/inode.c | 25 + fs/btrfs/ioctl.c | 8 fs/btrfs/root-tree.c | 2 +- fs/btrfs/transaction.c | 7 +-- fs/btrfs/xattr.c | 2 +- 6 files changed, 26 insertions(+), 22 deletions(-) diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index 098bb8f..610f569 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -2544,7 +2544,7 @@ out_trans: goto out_free; inode_inc_iversion(inode); - inode->i_mtime = inode->i_ctime = CURRENT_TIME; + inode->i_mtime = inode->i_ctime = current_fs_time(inode->i_sb); trans->block_rsv = >fs_info->trans_block_rsv; ret = btrfs_update_inode(trans, root, inode); @@ -2794,7 +2794,7 @@ static long btrfs_fallocate(struct file *file, int mode, if (IS_ERR(trans)) { ret = PTR_ERR(trans); } else { - inode->i_ctime = CURRENT_TIME; + inode->i_ctime = current_fs_time(inode->i_sb); i_size_write(inode, actual_end); btrfs_ordered_update_i_size(inode, actual_end, NULL); ret = btrfs_update_inode(trans, root, inode); diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index e28f3d4..59c0e22 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -4013,7 +4013,8 @@ err: btrfs_i_size_write(dir, dir->i_size - name_len * 2); inode_inc_iversion(inode); inode_inc_iversion(dir); - inode->i_ctime = dir->i_mtime = dir->i_ctime = CURRENT_TIME; + inode->i_ctime = dir->i_mtime = + dir->i_ctime = current_fs_time(inode->i_sb); ret = btrfs_update_inode(trans, root, dir); out: return ret; @@ -4156,7 +4157,7 @@ int btrfs_unlink_subvol(struct btrfs_trans_handle *trans, btrfs_i_size_write(dir, dir->i_size - name_len * 2); inode_inc_iversion(dir); - dir->i_mtime = dir->i_ctime = CURRENT_TIME; + dir->i_mtime = dir->i_ctime = current_fs_time(dir->i_sb); ret = btrfs_update_inode_fallback(trans, root, dir); if (ret) btrfs_abort_transaction(trans, root, ret); @@ -5588,7 +5589,7 @@ static struct inode *new_simple_dir(struct super_block *s, inode->i_op = _dir_ro_inode_operations; inode->i_fop = _dir_operations; inode->i_mode = S_IFDIR | S_IRUGO | S_IWUSR | S_IXUGO; - inode->i_mtime = CURRENT_TIME; + inode->i_mtime = current_fs_time(inode->i_sb); inode->i_atime = inode->i_mtime; inode->i_ctime = inode->i_mtime; BTRFS_I(inode)->i_otime = inode->i_mtime; @@ -6160,7 +6161,7 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans, inode_init_owner(inode, dir, mode); inode_set_bytes(inode, 0); - inode->i_mtime = CURRENT_TIME; + inode->i_mtime = current_fs_time(inode->i_sb); inode->i_atime = inode->i_mtime; inode->i_ctime = inode->i_mtime; BTRFS_I(inode)->i_otime = inode->i_mtime; @@ -6273,7 +6274,8 @@ int btrfs_add_link(struct btrfs_trans_handle *trans, btrfs_i_size_write(parent_inode, parent_inode->i_size + name_len * 2); inode_inc_iversion(parent_inode); - parent_inode->i_mtime = parent_inode->i_ctime = CURRENT_TIME; + parent_inode->i_mtime = parent_inode->i_ctime = + current_fs_time(parent_inode->i_sb); ret = btrfs_update_inode(trans, root, parent_inode); if (ret) btrfs_abort_transaction(trans, root, ret); @@ -6491,7 +6493,7 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir, BTRFS_I(inode)->dir_index = 0ULL; inc_nlink(inode); inode_inc_iversion(inode); - inode->i_ctime = CURRENT_TIME; + inode->i_ctime = current_fs_time(inode->i_sb); ihold(inode); set_bit(BTRFS_INODE_COPY_EVERYTHING, _I(inode)->runtime_flags); @@ -9234,7 +9236,6 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry, struct btrfs_root *dest = BTRFS_I(new_dir)->root; struct inode *new_inode = d_inode(new_dentry); struct inode *old_inode = d_inode(old_dentry); - struct timespec ctime = CURRENT_TIME; u64 index = 0; u64 root_objectid; int ret; @@ -9331,9 +9332,9 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry, inode_inc_iversion(old_dir); inode_inc_iversion(new_dir); inode_inc_iversion(old_inode); - old_dir->i_ctime = old_dir->i_mtime = ctime; -
[Y2038] [PATCH 09/10] fs: ceph: Replace CURRENT_TIME by ktime_get_real_ts()
This is in preparation for the series that transitions filesystem timestamps to use 64 bit time and hence make them y2038 safe. CURRENT_TIME macro will be deleted before merging the aforementioned series. Filesystems will use current_fs_time() instead of CURRENT_TIME. Use ktime_get_real_ts() here as this is not filesystem time. ktime_get_real_ts() returns the timestamp in ns which can be used to calculate MDS request timestamp. Signed-off-by: Deepa DinamaniCc: "Yan, Zheng" Cc: Sage Weil Cc: Ilya Dryomov Cc: ceph-de...@vger.kernel.org --- fs/ceph/mds_client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c index e7b130a..348b22e 100644 --- a/fs/ceph/mds_client.c +++ b/fs/ceph/mds_client.c @@ -1721,7 +1721,7 @@ ceph_mdsc_create_request(struct ceph_mds_client *mdsc, int op, int mode) init_completion(>r_safe_completion); INIT_LIST_HEAD(>r_unsafe_item); - req->r_stamp = CURRENT_TIME; + ktime_get_real_ts(>r_stamp); req->r_op = op; req->r_direct_mode = mode; -- 1.9.1 ___ Y2038 mailing list Y2038@lists.linaro.org https://lists.linaro.org/mailman/listinfo/y2038
[Y2038] [PATCH 06/10] fs: ext4: Replace CURRENT_TIME_SEC with current_fs_time_sec()
The macro CURRENT_TIME_SEC does not represent filesystem times correctly as it cannot perform range checks. current_fs_time_sec() will be extended to include this. CURRENT_TIME_SEC is also not y2038 safe. current_fs_time_sec() will be transitioned to use 64 bit time along with vfs in a separate series. Signed-off-by: Deepa DinamaniCc: "Theodore Ts'o" Cc: Andreas Dilger Cc: linux-e...@vger.kernel.org --- fs/ext4/ext4.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 0662b28..8dd04f8 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -1489,7 +1489,7 @@ static inline struct ext4_inode_info *EXT4_I(struct inode *inode) static inline struct timespec ext4_current_time(struct inode *inode) { return (inode->i_sb->s_time_gran < NSEC_PER_SEC) ? - current_fs_time(inode->i_sb) : CURRENT_TIME_SEC; + current_fs_time(inode->i_sb) : current_fs_time_sec(inode->i_sb); } static inline int ext4_valid_inum(struct super_block *sb, unsigned long ino) -- 1.9.1 ___ Y2038 mailing list Y2038@lists.linaro.org https://lists.linaro.org/mailman/listinfo/y2038
Re: [Y2038] [PATCH 08/10] fs: ceph: replace CURRENT_TIME by current_fs_time()
> On Feb 3, 2016, at 14:07, Deepa Dinamaniwrote: > > CURRENT_TIME macro is not appropriate for filesystems as it > doesn't use the right granularity for filesystem timestamps. > Use current_fs_time() instead. > > Signed-off-by: Deepa Dinamani > Cc: "Yan, Zheng" > Cc: Sage Weil > Cc: Ilya Dryomov > Cc: ceph-de...@vger.kernel.org applied, thanks Yan, Zheng > --- > fs/ceph/file.c | 4 ++-- > fs/ceph/inode.c | 2 +- > fs/ceph/xattr.c | 4 ++-- > 3 files changed, 5 insertions(+), 5 deletions(-) > > diff --git a/fs/ceph/file.c b/fs/ceph/file.c > index 86a9c38..9b338ff 100644 > --- a/fs/ceph/file.c > +++ b/fs/ceph/file.c > @@ -783,7 +783,7 @@ ceph_direct_read_write(struct kiocb *iocb, struct > iov_iter *iter, > int num_pages = 0; > int flags; > int ret; > - struct timespec mtime = CURRENT_TIME; > + struct timespec mtime = current_fs_time(inode->i_sb); > size_t count = iov_iter_count(iter); > loff_t pos = iocb->ki_pos; > bool write = iov_iter_rw(iter) == WRITE; > @@ -988,7 +988,7 @@ ceph_sync_write(struct kiocb *iocb, struct iov_iter > *from, loff_t pos, > int flags; > int check_caps = 0; > int ret; > - struct timespec mtime = CURRENT_TIME; > + struct timespec mtime = current_fs_time(inode->i_sb); > size_t count = iov_iter_count(from); > > if (ceph_snap(file_inode(file)) != CEPH_NOSNAP) > diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c > index fb4ba2e..63d0198 100644 > --- a/fs/ceph/inode.c > +++ b/fs/ceph/inode.c > @@ -1959,7 +1959,7 @@ int ceph_setattr(struct dentry *dentry, struct iattr > *attr) > if (dirtied) { > inode_dirty_flags = __ceph_mark_dirty_caps(ci, dirtied, > _cf); > - inode->i_ctime = CURRENT_TIME; > + inode->i_ctime = current_fs_time(inode->i_sb); > } > > release &= issued; > diff --git a/fs/ceph/xattr.c b/fs/ceph/xattr.c > index 819163d..1e1c00a 100644 > --- a/fs/ceph/xattr.c > +++ b/fs/ceph/xattr.c > @@ -999,7 +999,7 @@ retry: > dirty = __ceph_mark_dirty_caps(ci, CEPH_CAP_XATTR_EXCL, > _cf); > ci->i_xattrs.dirty = true; > - inode->i_ctime = CURRENT_TIME; > + inode->i_ctime = current_fs_time(inode->i_sb); > } > > spin_unlock(>i_ceph_lock); > @@ -1136,7 +1136,7 @@ retry: > dirty = __ceph_mark_dirty_caps(ci, CEPH_CAP_XATTR_EXCL, > _cf); > ci->i_xattrs.dirty = true; > - inode->i_ctime = CURRENT_TIME; > + inode->i_ctime = current_fs_time(inode->i_sb); > spin_unlock(>i_ceph_lock); > if (lock_snap_rwsem) > up_read(>snap_rwsem); > -- > 1.9.1 > ___ Y2038 mailing list Y2038@lists.linaro.org https://lists.linaro.org/mailman/listinfo/y2038