Merge tag 'vfs-6.7.fsid' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs
[sfrench/cifs-2.6.git] / fs / libfs.c
index 38950cce135b72791d1bb099a382354b025240e8..e9440d55073c50962486f3f4f047a7872544fcff 100644 (file)
@@ -544,7 +544,8 @@ void simple_recursive_removal(struct dentry *dentry,
                                dput(victim);           // unpin it
                        }
                        if (victim == dentry) {
-                               inode->i_mtime = inode_set_ctime_current(inode);
+                               inode_set_mtime_to_ts(inode,
+                                                     inode_set_ctime_current(inode));
                                if (d_is_dir(dentry))
                                        drop_nlink(inode);
                                inode_unlock(inode);
@@ -585,7 +586,7 @@ static int pseudo_fs_fill_super(struct super_block *s, struct fs_context *fc)
         */
        root->i_ino = 1;
        root->i_mode = S_IFDIR | S_IRUSR | S_IWUSR;
-       root->i_atime = root->i_mtime = inode_set_ctime_current(root);
+       simple_inode_init_ts(root);
        s->s_root = d_make_root(root);
        if (!s->s_root)
                return -ENOMEM;
@@ -641,8 +642,8 @@ int simple_link(struct dentry *old_dentry, struct inode *dir, struct dentry *den
 {
        struct inode *inode = d_inode(old_dentry);
 
-       dir->i_mtime = inode_set_ctime_to_ts(dir,
-                                            inode_set_ctime_current(inode));
+       inode_set_mtime_to_ts(dir,
+                             inode_set_ctime_to_ts(dir, inode_set_ctime_current(inode)));
        inc_nlink(inode);
        ihold(inode);
        dget(dentry);
@@ -676,8 +677,8 @@ int simple_unlink(struct inode *dir, struct dentry *dentry)
 {
        struct inode *inode = d_inode(dentry);
 
-       dir->i_mtime = inode_set_ctime_to_ts(dir,
-                                            inode_set_ctime_current(inode));
+       inode_set_mtime_to_ts(dir,
+                             inode_set_ctime_to_ts(dir, inode_set_ctime_current(inode)));
        drop_nlink(inode);
        dput(dentry);
        return 0;
@@ -712,9 +713,10 @@ void simple_rename_timestamp(struct inode *old_dir, struct dentry *old_dentry,
 {
        struct inode *newino = d_inode(new_dentry);
 
-       old_dir->i_mtime = inode_set_ctime_current(old_dir);
+       inode_set_mtime_to_ts(old_dir, inode_set_ctime_current(old_dir));
        if (new_dir != old_dir)
-               new_dir->i_mtime = inode_set_ctime_current(new_dir);
+               inode_set_mtime_to_ts(new_dir,
+                                     inode_set_ctime_current(new_dir));
        inode_set_ctime_current(d_inode(old_dentry));
        if (newino)
                inode_set_ctime_current(newino);
@@ -929,7 +931,7 @@ int simple_fill_super(struct super_block *s, unsigned long magic,
         */
        inode->i_ino = 1;
        inode->i_mode = S_IFDIR | 0755;
-       inode->i_atime = inode->i_mtime = inode_set_ctime_current(inode);
+       simple_inode_init_ts(inode);
        inode->i_op = &simple_dir_inode_operations;
        inode->i_fop = &simple_dir_operations;
        set_nlink(inode, 2);
@@ -955,7 +957,7 @@ int simple_fill_super(struct super_block *s, unsigned long magic,
                        goto out;
                }
                inode->i_mode = S_IFREG | files->mode;
-               inode->i_atime = inode->i_mtime = inode_set_ctime_current(inode);
+               simple_inode_init_ts(inode);
                inode->i_fop = files->ops;
                inode->i_ino = i;
                d_add(dentry, inode);
@@ -1564,7 +1566,7 @@ struct inode *alloc_anon_inode(struct super_block *s)
        inode->i_uid = current_fsuid();
        inode->i_gid = current_fsgid();
        inode->i_flags |= S_PRIVATE;
-       inode->i_atime = inode->i_mtime = inode_set_ctime_current(inode);
+       simple_inode_init_ts(inode);
        return inode;
 }
 EXPORT_SYMBOL(alloc_anon_inode);
@@ -1956,3 +1958,20 @@ ssize_t direct_write_fallback(struct kiocb *iocb, struct iov_iter *iter,
        return direct_written + buffered_written;
 }
 EXPORT_SYMBOL_GPL(direct_write_fallback);
+
+/**
+ * simple_inode_init_ts - initialize the timestamps for a new inode
+ * @inode: inode to be initialized
+ *
+ * When a new inode is created, most filesystems set the timestamps to the
+ * current time. Add a helper to do this.
+ */
+struct timespec64 simple_inode_init_ts(struct inode *inode)
+{
+       struct timespec64 ts = inode_set_ctime_current(inode);
+
+       inode_set_atime_to_ts(inode, ts);
+       inode_set_mtime_to_ts(inode, ts);
+       return ts;
+}
+EXPORT_SYMBOL(simple_inode_init_ts);