Skip to content

Commit aa08185

Browse files
Ronnie SahlbergSteve French
authored andcommitted
cifs: flush before set-info if we have writeable handles
Servers can defer destaging any data and updating the mtime until close(). This means that if we do a setinfo to modify the mtime while other handles are open for write the server may overwrite our setinfo timestamps when if flushes the file on close() of the writeable handle. To solve this we add an explicit flush when the mtime is about to be updated. This fixes "cp -p" to preserve mtime when copying a file onto an SMB2 share. CC: Stable <[email protected]> Signed-off-by: Ronnie Sahlberg <[email protected]> Reviewed-by: Pavel Shilovsky <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 89a5bfa commit aa08185

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

fs/cifs/inode.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2406,6 +2406,8 @@ cifs_setattr_nounix(struct dentry *direntry, struct iattr *attrs)
24062406
struct inode *inode = d_inode(direntry);
24072407
struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
24082408
struct cifsInodeInfo *cifsInode = CIFS_I(inode);
2409+
struct cifsFileInfo *wfile;
2410+
struct cifs_tcon *tcon;
24092411
char *full_path = NULL;
24102412
int rc = -EACCES;
24112413
__u32 dosattr = 0;
@@ -2452,6 +2454,20 @@ cifs_setattr_nounix(struct dentry *direntry, struct iattr *attrs)
24522454
mapping_set_error(inode->i_mapping, rc);
24532455
rc = 0;
24542456

2457+
if (attrs->ia_valid & ATTR_MTIME) {
2458+
rc = cifs_get_writable_file(cifsInode, false, &wfile);
2459+
if (!rc) {
2460+
tcon = tlink_tcon(wfile->tlink);
2461+
rc = tcon->ses->server->ops->flush(xid, tcon, &wfile->fid);
2462+
cifsFileInfo_put(wfile);
2463+
if (rc)
2464+
return rc;
2465+
} else if (rc != -EBADF)
2466+
return rc;
2467+
else
2468+
rc = 0;
2469+
}
2470+
24552471
if (attrs->ia_valid & ATTR_SIZE) {
24562472
rc = cifs_set_file_size(inode, attrs, xid, full_path);
24572473
if (rc != 0)

0 commit comments

Comments
 (0)