CIFS: Respect O_SYNC and O_DIRECT flags during reconnect
diff mbox series

Message ID 20191113011635.3511-1-pshilov@microsoft.com
State New
Headers show
Series
  • CIFS: Respect O_SYNC and O_DIRECT flags during reconnect
Related show

Commit Message

Pavel Shilovsky Nov. 13, 2019, 1:16 a.m. UTC
Currently the client translates O_SYNC and O_DIRECT flags
into corresponding SMB create options when openning a file.
The problem is that on reconnect when the file is being
re-opened the client doesn't set those flags and it causes
a server to reject re-open requests because create options
don't match. The latter means that any subsequent system
call against that open file fail until a share is re-mounted.

Fix this by properly setting SMB create options when
re-openning files after reconnects.

Fixes: 1013e760d10e6: ("SMB3: Don't ignore O_SYNC/O_DSYNC and O_DIRECT flags")
Cc: Stable <stable@vger.kernel.org>
Signed-off-by: Pavel Shilovsky <pshilov@microsoft.com>
---
 fs/cifs/file.c | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Ronnie Sahlberg Nov. 13, 2019, 3:32 a.m. UTC | #1
Reviewed-by: Ronnie Sahlberg <lsahlber@redhat.com>


----- Original Message -----
From: "Pavel Shilovsky" <piastryyy@gmail.com>
To: linux-cifs@vger.kernel.org, smfrench@gmail.com
Sent: Wednesday, 13 November, 2019 11:16:35 AM
Subject: [PATCH] CIFS: Respect O_SYNC and O_DIRECT flags during reconnect

Currently the client translates O_SYNC and O_DIRECT flags
into corresponding SMB create options when openning a file.
The problem is that on reconnect when the file is being
re-opened the client doesn't set those flags and it causes
a server to reject re-open requests because create options
don't match. The latter means that any subsequent system
call against that open file fail until a share is re-mounted.

Fix this by properly setting SMB create options when
re-openning files after reconnects.

Fixes: 1013e760d10e6: ("SMB3: Don't ignore O_SYNC/O_DSYNC and O_DIRECT flags")
Cc: Stable <stable@vger.kernel.org>
Signed-off-by: Pavel Shilovsky <pshilov@microsoft.com>
---
 fs/cifs/file.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index b6f544bc6c73..89617bb058ae 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -721,6 +721,13 @@ cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush)
 	if (backup_cred(cifs_sb))
 		create_options |= CREATE_OPEN_BACKUP_INTENT;
 
+	/* O_SYNC also has bit for O_DSYNC so following check picks up either */
+	if (cfile->f_flags & O_SYNC)
+		create_options |= CREATE_WRITE_THROUGH;
+
+	if (cfile->f_flags & O_DIRECT)
+		create_options |= CREATE_NO_BUFFER;
+
 	if (server->ops->get_lease_key)
 		server->ops->get_lease_key(inode, &cfile->fid);
Steve French Nov. 13, 2019, 5:36 a.m. UTC | #2
merged into cifs-2.6.git for-next and also updated the github tree
(used by the buildbot e.g.)

On Tue, Nov 12, 2019 at 9:32 PM Ronnie Sahlberg <lsahlber@redhat.com> wrote:
>
> Reviewed-by: Ronnie Sahlberg <lsahlber@redhat.com>
>
>
> ----- Original Message -----
> From: "Pavel Shilovsky" <piastryyy@gmail.com>
> To: linux-cifs@vger.kernel.org, smfrench@gmail.com
> Sent: Wednesday, 13 November, 2019 11:16:35 AM
> Subject: [PATCH] CIFS: Respect O_SYNC and O_DIRECT flags during reconnect
>
> Currently the client translates O_SYNC and O_DIRECT flags
> into corresponding SMB create options when openning a file.
> The problem is that on reconnect when the file is being
> re-opened the client doesn't set those flags and it causes
> a server to reject re-open requests because create options
> don't match. The latter means that any subsequent system
> call against that open file fail until a share is re-mounted.
>
> Fix this by properly setting SMB create options when
> re-openning files after reconnects.
>
> Fixes: 1013e760d10e6: ("SMB3: Don't ignore O_SYNC/O_DSYNC and O_DIRECT flags")
> Cc: Stable <stable@vger.kernel.org>
> Signed-off-by: Pavel Shilovsky <pshilov@microsoft.com>
> ---
>  fs/cifs/file.c | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/fs/cifs/file.c b/fs/cifs/file.c
> index b6f544bc6c73..89617bb058ae 100644
> --- a/fs/cifs/file.c
> +++ b/fs/cifs/file.c
> @@ -721,6 +721,13 @@ cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush)
>         if (backup_cred(cifs_sb))
>                 create_options |= CREATE_OPEN_BACKUP_INTENT;
>
> +       /* O_SYNC also has bit for O_DSYNC so following check picks up either */
> +       if (cfile->f_flags & O_SYNC)
> +               create_options |= CREATE_WRITE_THROUGH;
> +
> +       if (cfile->f_flags & O_DIRECT)
> +               create_options |= CREATE_NO_BUFFER;
> +
>         if (server->ops->get_lease_key)
>                 server->ops->get_lease_key(inode, &cfile->fid);
>
> --
> 2.17.1
>

Patch
diff mbox series

diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index b6f544bc6c73..89617bb058ae 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -721,6 +721,13 @@  cifs_reopen_file(struct cifsFileInfo *cfile, bool can_flush)
 	if (backup_cred(cifs_sb))
 		create_options |= CREATE_OPEN_BACKUP_INTENT;
 
+	/* O_SYNC also has bit for O_DSYNC so following check picks up either */
+	if (cfile->f_flags & O_SYNC)
+		create_options |= CREATE_WRITE_THROUGH;
+
+	if (cfile->f_flags & O_DIRECT)
+		create_options |= CREATE_NO_BUFFER;
+
 	if (server->ops->get_lease_key)
 		server->ops->get_lease_key(inode, &cfile->fid);