ubifs: use timespec64 for inode timestamps
Subsystems (2)
PATCH RESEND 1/2 ubifs: use timespec64 for inode timestamps
Both vfs and the on-disk inode structures can deal with fine-grained timestamps now, so this is the last missing piece to make ubifs y2038-safe on 32-bit architectures.
---
I sent these two patches originally on Jun 20, but forgot to write back when Richard asked who should apply them.
Please pick up both patches in the ubifs tree for 4.19.
--- fs/ubifs/file.c | 11 +++++------ fs/ubifs/sb.c | 6 +++--- 2 files changed, 8 insertions(+), 9 deletions(-)
fs/ubifs/file.c +5 -6
@@ -1365,11 +1365,10 @@ int ubifs_fsync(struct file *file, loff_t start, loff_t end, int datasync)* granularity, they are not updated. This is an optimization. */ static inline int mctime_update_needed (const struct inode *inode, -const struct timespec *now) +const struct timespec64 *now) { -struct timespec64 now64 =timespec_to_timespec64 (*now); -if (!timespec64_equal (&inode->i_mtime, &now64) || - !timespec64_equal (&inode->i_ctime, &now64)) +if (!timespec64_equal (&inode->i_mtime, now) || + !timespec64_equal (&inode->i_ctime, now))return 1 ;return 0 ; }
@@ -1425,7 +1424,7 @@ int ubifs_update_time(struct inode *inode, struct timespec64 *time,*/ static int update_mctime (struct inode *inode) { -struct timespec now =timespec64_to_timespec (current_time (inode)); +struct timespec64 now =current_time (inode);struct ubifs_inode *ui =ubifs_inode (inode);struct ubifs_info *c = inode->i_sb->s_fs_info;
@@ -1519,7 +1518,7 @@ static vm_fault_t ubifs_vm_page_mkwrite(struct vm_fault *vmf)struct page *page = vmf->page;struct inode *inode =file_inode (vmf->vma->vm_file);struct ubifs_info *c = inode->i_sb->s_fs_info; -struct timespec now =timespec64_to_timespec (current_time (inode)); +struct timespec64 now =current_time (inode);struct ubifs_budget_req req = { .new_page =1 };int err, update_time;
fs/ubifs/sb.c +3 -3
@@ -85,7 +85,7 @@ static int create_default_filesystem(struct ubifs_info *c)long long tmp64, main_bytes;__le64 tmp_le64;__le32 tmp_le32; -struct timespec ts; +struct timespec64 ts;/* Some functions called from here depend on the @c->key_len filed */ c->key_len =UBIFS_SK_LEN ;
@@ -301,8 +301,8 @@ static int create_default_filesystem(struct ubifs_info *c) ino->creat_sqnum =cpu_to_le64 (++c->max_sqnum); ino->nlink =cpu_to_le32 (2 ); -ktime_get_real_ts (&ts); - ts =timespec_trunc (ts,DEFAULT_TIME_GRAN ); +ktime_get_real_ts64 (&ts); + ts =timespec64_trunc (ts,DEFAULT_TIME_GRAN ); tmp_le64 =cpu_to_le64 (ts.tv_sec); ino->atime_sec = tmp_le64; ino->ctime_sec = tmp_le64;
Signature · 1 line
2.9.0
PATCH RESEND 2/2 ubifs: tnc: use monotonic znode timestamp
The tnc uses get_seconds() based timestamps to check the age of a znode, which has two problems: on 32-bit architectures this may overflow in 2038 or 2106, and it gives incorrect information when the system time is updated using settimeofday().
Using montonic timestamps with ktime_get_seconds() solves both thes problems.
--- fs/ubifs/shrinker.c | 2 +- fs/ubifs/tnc.c | 4 ++-- fs/ubifs/tnc_misc.c | 2 +- fs/ubifs/ubifs.h | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-)
fs/ubifs/shrinker.c +1 -1
@@ -71,7 +71,7 @@ static int shrink_tnc(struct ubifs_info *c, int nr, int age, int *contention) {int total_freed =0 ;struct ubifs_znode *znode, *zprev; -int time =get_seconds (); +time64_t time =ktime_get_seconds ();ubifs_assert (mutex_is_locked (&c->umount_mutex));ubifs_assert (mutex_is_locked (&c->tnc_mutex));
fs/ubifs/tnc.c +2 -2
@@ -1179,7 +1179,7 @@ int ubifs_lookup_level0(struct ubifs_info *c, const union ubifs_key *key, {int err, exact;struct ubifs_znode *znode; -unsigned long time =get_seconds (); +time64_t time =ktime_get_seconds ();dbg_tnck (key,"search key " );ubifs_assert (key_type (c, key) <UBIFS_INVALID_KEY );
@@ -1315,7 +1315,7 @@ static int lookup_level0_dirty(struct ubifs_info *c, const union ubifs_key *key, {int err, exact;struct ubifs_znode *znode; -unsigned long time =get_seconds (); +time64_t time =ktime_get_seconds ();dbg_tnck (key,"search and dirty key " );
fs/ubifs/tnc_misc.c +1 -1
@@ -435,7 +435,7 @@ struct ubifs_znode *ubifs_load_znode(struct ubifs_info *c, zbr->znode = znode; znode->parent = parent; - znode->time =get_seconds (); + znode->time =ktime_get_seconds (); znode->iip = iip;return znode;
fs/ubifs/ubifs.h +1 -1
@@ -758,7 +758,7 @@ struct ubifs_znode {struct ubifs_znode *parent;struct ubifs_znode *cnext;unsigned long flags; -unsigned long time; +time64_t time;int level;int child_cnt;int iip;
Signature · 1 line
2.9.0