Skip to contentSkip to conversation

afs: Fix setting of mtime when creating a file/dir/symlink

PATCH In review David Howells 3 participants 3 messages May 31, 2023 – Jun 1, 2023

Subsystems (2)
lore
Share & tools
lore

David Howells

author maintainer
#0 lore raw

PATCH 1/1 afs: Fix setting of mtime when creating a file/dir/symlink

kafs incorrectly passes a zero mtime (ie. 1st Jan 1970) to the server when creating a file, dir or symlink because commit 52af7105eceb caused the mtime recorded in the afs_operation struct to be passed to the server, but didn't modify the afs_mkdir(), afs_create() and afs_symlink() functions to set it first.

Those functions were written with the assumption that the mtime would be obtained from the server - but that fell foul of malsynchronised clocks, so it was decided that the mtime should be set from the client instead.

Fix this by filling in op->mtime before calling the create op.

Fixes 52af7105eceb ("afs: Set mtime from the client for yfs create operations")
cc Marc Dionne <[email protected]>
---
 fs/afs/dir.c |    3 +++
 1 file changed, 3 insertions(+)
fs/afs/dir.c +3 -0
index 4dd97afa536c..5219182e52e1 100644
@@ -1358,6 +1358,7 @@ static int afs_mkdir(struct mnt_idmap *idmap, struct inode *dir,
 	op->dentry	= dentry;
 	op->create.mode	= S_IFDIR | mode;
 	op->create.reason = afs_edit_dir_for_mkdir;
+	op->mtime	= current_time(dir);
 	op->ops		= &afs_mkdir_operation;
 	return afs_do_sync_operation(op);
 }
@@ -1661,6 +1662,7 @@ static int afs_create(struct mnt_idmap *idmap, struct inode *dir,
 	op->dentry	= dentry;
 	op->create.mode	= S_IFREG | mode;
 	op->create.reason = afs_edit_dir_for_create;
+	op->mtime	= current_time(dir);
 	op->ops		= &afs_create_operation;
 	return afs_do_sync_operation(op);
 
@@ -1796,6 +1798,7 @@ static int afs_symlink(struct mnt_idmap *idmap, struct inode *dir,
 	op->ops			= &afs_symlink_operation;
 	op->create.reason	= afs_edit_dir_for_symlink;
 	op->create.symlink	= content;
+	op->mtime		= current_time(dir);
 	return afs_do_sync_operation(op);
 
 error:
Reviewed-by on v1 1/1
#1 lore raw
Quoted 44 lines · David Howells

kafs incorrectly passes a zero mtime (ie. 1st Jan 1970) to the server when creating a file, dir or symlink because commit 52af7105eceb caused the mtime recorded in the afs_operation struct to be passed to the server, but didn't modify the afs_mkdir(), afs_create() and afs_symlink() functions to set it first.

Those functions were written with the assumption that the mtime would be obtained from the server - but that fell foul of malsynchronised clocks, so it was decided that the mtime should be set from the client instead.

Fix this by filling in op->mtime before calling the create op.

Fixes 52af7105eceb ("afs: Set mtime from the client for yfs create operations")
cc Marc Dionne <[email protected]>
---
  fs/afs/dir.c |    3 +++
  1 file changed, 3 insertions(+)
fs/afs/dir.c +2 -0
index 4dd97afa536c..5219182e52e1 100644
@@ -1358,6 +1358,7 @@ static int afs_mkdir(struct mnt_idmap *idmap, struct inode *dir,
  	op->dentry	= dentry;
  	op->create.mode	= S_IFDIR | mode;
  	op->create.reason = afs_edit_dir_for_mkdir;
+	op->mtime	= current_time(dir);
  	op->ops		= &afs_mkdir_operation;
  	return afs_do_sync_operation(op);
  }
@@ -1661,6 +1662,7 @@ static int afs_create(struct mnt_idmap *idmap, struct inode *dir,
  	op->dentry	= dentry;
  	op->create.mode	= S_IFREG | mode;
  	op->create.reason = afs_edit_dir_for_create;
+	op->mtime	= current_time(dir);
  	op->ops		= &afs_create_operation;
  	return afs_do_sync_operation(op);
 

fs/afs/dir.c static int afs_symlink(struct mnt_idmap *idmap, struct inode *dir, · line 1804

Quoted 7 lines
fs/afs/dir.c +1 -0
@@ -1796,6 +1798,7 @@ static int afs_symlink(struct mnt_idmap *idmap, struct inode *dir,
  	op->ops			= &afs_symlink_operation;
  	op->create.reason	= afs_edit_dir_for_symlink;
  	op->create.symlink	= content;
+	op->mtime		= current_time(dir);
  	return afs_do_sync_operation(op);
 
  error:
maintainer
#2 lore raw
In reply to David Howells
Quoted 44 lines · David Howells

kafs incorrectly passes a zero mtime (ie. 1st Jan 1970) to the server when creating a file, dir or symlink because commit 52af7105eceb caused the mtime recorded in the afs_operation struct to be passed to the server, but didn't modify the afs_mkdir(), afs_create() and afs_symlink() functions to set it first.

Those functions were written with the assumption that the mtime would be obtained from the server - but that fell foul of malsynchronised clocks, so it was decided that the mtime should be set from the client instead.

Fix this by filling in op->mtime before calling the create op.

Fixes 52af7105eceb ("afs: Set mtime from the client for yfs create operations")
cc Marc Dionne <[email protected]>
---
 fs/afs/dir.c |    3 +++
 1 file changed, 3 insertions(+)
fs/afs/dir.c +2 -0
index 4dd97afa536c..5219182e52e1 100644
@@ -1358,6 +1358,7 @@ static int afs_mkdir(struct mnt_idmap *idmap, struct inode *dir,
        op->dentry      = dentry;
        op->create.mode = S_IFDIR | mode;
        op->create.reason = afs_edit_dir_for_mkdir;
+       op->mtime       = current_time(dir);
        op->ops         = &afs_mkdir_operation;
        return afs_do_sync_operation(op);
 }
@@ -1661,6 +1662,7 @@ static int afs_create(struct mnt_idmap *idmap, struct inode *dir,
        op->dentry      = dentry;
        op->create.mode = S_IFREG | mode;
        op->create.reason = afs_edit_dir_for_create;
+       op->mtime       = current_time(dir);
        op->ops         = &afs_create_operation;
        return afs_do_sync_operation(op);
 

fs/afs/dir.c static int afs_symlink(struct mnt_idmap *idmap, struct inode *dir, · line 1804

Quoted 7 lines
fs/afs/dir.c +1 -0
@@ -1796,6 +1798,7 @@ static int afs_symlink(struct mnt_idmap *idmap, struct inode *dir,
        op->ops                 = &afs_symlink_operation;
        op->create.reason       = afs_edit_dir_for_symlink;
        op->create.symlink      = content;
+       op->mtime               = current_time(dir);
        return afs_do_sync_operation(op);
 
 error:

The fix looks good, but as we discussed privately, the issue that this fixes predates commit 52af7105eceb. That commit only touched the yfs client code and made it rely on the op mtime rather than letting the server set the time. This made it inherit the issue that was already present for the non yfs client code.

Marc