Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2eacc0ac authored by Steve French's avatar Steve French Committed by Greg Kroah-Hartman
Browse files

smb3: do not error on fsync when readonly



[ Upstream commit 71e6864eacbef0b2645ca043cdfbac272cb6cea3 ]

Linux allows doing a flush/fsync on a file open for read-only,
but the protocol does not allow that.  If the file passed in
on the flush is read-only try to find a writeable handle for
the same inode, if that is not possible skip sending the
fsync call to the server to avoid breaking the apps.

Reported-by: default avatarJulian Sikorski <belegdol@gmail.com>
Tested-by: default avatarJulian Sikorski <belegdol@gmail.com>
Suggested-by: default avatarJeremy Allison <jra@samba.org>
Reviewed-by: default avatarPaulo Alcantara (SUSE) <pc@cjr.nz>
Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent 51be334d
Loading
Loading
Loading
Loading
+29 −6
Original line number Original line Diff line number Diff line
@@ -2577,12 +2577,23 @@ int cifs_strict_fsync(struct file *file, loff_t start, loff_t end,
	tcon = tlink_tcon(smbfile->tlink);
	tcon = tlink_tcon(smbfile->tlink);
	if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOSSYNC)) {
	if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOSSYNC)) {
		server = tcon->ses->server;
		server = tcon->ses->server;
		if (server->ops->flush)
		if (server->ops->flush == NULL) {
			rc = server->ops->flush(xid, tcon, &smbfile->fid);
		else
			rc = -ENOSYS;
			rc = -ENOSYS;
			goto strict_fsync_exit;
		}
		}


		if ((OPEN_FMODE(smbfile->f_flags) & FMODE_WRITE) == 0) {
			smbfile = find_writable_file(CIFS_I(inode), FIND_WR_ANY);
			if (smbfile) {
				rc = server->ops->flush(xid, tcon, &smbfile->fid);
				cifsFileInfo_put(smbfile);
			} else
				cifs_dbg(FYI, "ignore fsync for file not open for write\n");
		} else
			rc = server->ops->flush(xid, tcon, &smbfile->fid);
	}

strict_fsync_exit:
	free_xid(xid);
	free_xid(xid);
	return rc;
	return rc;
}
}
@@ -2594,6 +2605,7 @@ int cifs_fsync(struct file *file, loff_t start, loff_t end, int datasync)
	struct cifs_tcon *tcon;
	struct cifs_tcon *tcon;
	struct TCP_Server_Info *server;
	struct TCP_Server_Info *server;
	struct cifsFileInfo *smbfile = file->private_data;
	struct cifsFileInfo *smbfile = file->private_data;
	struct inode *inode = file_inode(file);
	struct cifs_sb_info *cifs_sb = CIFS_FILE_SB(file);
	struct cifs_sb_info *cifs_sb = CIFS_FILE_SB(file);


	rc = file_write_and_wait_range(file, start, end);
	rc = file_write_and_wait_range(file, start, end);
@@ -2608,12 +2620,23 @@ int cifs_fsync(struct file *file, loff_t start, loff_t end, int datasync)
	tcon = tlink_tcon(smbfile->tlink);
	tcon = tlink_tcon(smbfile->tlink);
	if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOSSYNC)) {
	if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOSSYNC)) {
		server = tcon->ses->server;
		server = tcon->ses->server;
		if (server->ops->flush)
		if (server->ops->flush == NULL) {
			rc = server->ops->flush(xid, tcon, &smbfile->fid);
		else
			rc = -ENOSYS;
			rc = -ENOSYS;
			goto fsync_exit;
		}

		if ((OPEN_FMODE(smbfile->f_flags) & FMODE_WRITE) == 0) {
			smbfile = find_writable_file(CIFS_I(inode), FIND_WR_ANY);
			if (smbfile) {
				rc = server->ops->flush(xid, tcon, &smbfile->fid);
				cifsFileInfo_put(smbfile);
			} else
				cifs_dbg(FYI, "ignore fsync for file not open for write\n");
		} else
			rc = server->ops->flush(xid, tcon, &smbfile->fid);
	}
	}


fsync_exit:
	free_xid(xid);
	free_xid(xid);
	return rc;
	return rc;
}
}