linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cifs/smb3: directory sync should not return an error
@ 2018-05-10 16:04 Steve French
  2018-05-10 16:37 ` Jeremy Allison
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Steve French @ 2018-05-10 16:04 UTC (permalink / raw)
  To: CIFS; +Cc: linux-fsdevel, samba-technical

[-- Attachment #1: Type: text/plain, Size: 200 bytes --]

As with NFS, which ignores sync on directory handles,
fsync on a directory handle is a noop for CIFS/SMB3.
Do not return an error on it.  It breaks some database
apps otherwise.



-- 
Thanks,

Steve

[-- Attachment #2: 0001-smb3-directory-sync-should-not-return-an-error.patch --]
[-- Type: text/x-patch, Size: 1477 bytes --]

From 6112a4967573f9a347f7abc02e80423851b73737 Mon Sep 17 00:00:00 2001
From: Steve French <smfrench@gmail.com>
Date: Thu, 10 May 2018 10:59:37 -0500
Subject: [PATCH] smb3: directory sync should not return an error

As with NFS, which ignores sync on directory handles,
fsync on a directory handle is a noop for CIFS/SMB3.
Do not return an error on it.  It breaks some database
apps otherwise.

Signed-off-by: Steve French <smfrench@gmail.com>
CC: Stable <stable@vger.kernel.org>
---
 fs/cifs/cifsfs.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
index ed8e181927d6..8e41186d9923 100644
--- a/fs/cifs/cifsfs.c
+++ b/fs/cifs/cifsfs.c
@@ -1049,6 +1049,18 @@ ssize_t cifs_file_copychunk_range(unsigned int xid,
 	return rc;
 }
 
+/*
+ * Directory operations under CIFS/SMB2/SMB3 are synchronous, so fsync()
+ * is a dummy operation.
+ */
+int cifs_dir_fsync(struct file *file, loff_t start, loff_t end, int datasync)
+{
+	cifs_dbg(FYI, "Sync directory - name: %pD datasync: 0x%x\n",
+		 file, datasync);
+
+	return 0;
+}
+
 static ssize_t cifs_copy_file_range(struct file *src_file, loff_t off,
 				struct file *dst_file, loff_t destoff,
 				size_t len, unsigned int flags)
@@ -1183,6 +1195,7 @@ const struct file_operations cifs_dir_ops = {
 	.copy_file_range = cifs_copy_file_range,
 	.clone_file_range = cifs_clone_file_range,
 	.llseek = generic_file_llseek,
+	.fsync = cifs_dir_fsync,
 };
 
 static void
-- 
2.17.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH] cifs/smb3: directory sync should not return an error
  2018-05-10 16:04 [PATCH] cifs/smb3: directory sync should not return an error Steve French
@ 2018-05-10 16:37 ` Jeremy Allison
  2018-05-10 17:11 ` Pavel Shilovsky
  2018-05-10 21:01 ` ronnie sahlberg
  2 siblings, 0 replies; 11+ messages in thread
From: Jeremy Allison @ 2018-05-10 16:37 UTC (permalink / raw)
  To: Steve French; +Cc: CIFS, linux-fsdevel, samba-technical

On Thu, May 10, 2018 at 11:04:14AM -0500, Steve French via samba-technical wrote:
> As with NFS, which ignores sync on directory handles,
> fsync on a directory handle is a noop for CIFS/SMB3.
> Do not return an error on it.  It breaks some database
> apps otherwise.

Thanks for this. I now have an smbtorture test that
shows we handle flush on directories incorrectly.

Patch to follow.

Jeremy.

> -- 
> Thanks,
> 
> Steve

> From 6112a4967573f9a347f7abc02e80423851b73737 Mon Sep 17 00:00:00 2001
> From: Steve French <smfrench@gmail.com>
> Date: Thu, 10 May 2018 10:59:37 -0500
> Subject: [PATCH] smb3: directory sync should not return an error
> 
> As with NFS, which ignores sync on directory handles,
> fsync on a directory handle is a noop for CIFS/SMB3.
> Do not return an error on it.  It breaks some database
> apps otherwise.
> 
> Signed-off-by: Steve French <smfrench@gmail.com>
> CC: Stable <stable@vger.kernel.org>
> ---
>  fs/cifs/cifsfs.c | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
> 
> diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
> index ed8e181927d6..8e41186d9923 100644
> --- a/fs/cifs/cifsfs.c
> +++ b/fs/cifs/cifsfs.c
> @@ -1049,6 +1049,18 @@ ssize_t cifs_file_copychunk_range(unsigned int xid,
>  	return rc;
>  }
>  
> +/*
> + * Directory operations under CIFS/SMB2/SMB3 are synchronous, so fsync()
> + * is a dummy operation.
> + */
> +int cifs_dir_fsync(struct file *file, loff_t start, loff_t end, int datasync)
> +{
> +	cifs_dbg(FYI, "Sync directory - name: %pD datasync: 0x%x\n",
> +		 file, datasync);
> +
> +	return 0;
> +}
> +
>  static ssize_t cifs_copy_file_range(struct file *src_file, loff_t off,
>  				struct file *dst_file, loff_t destoff,
>  				size_t len, unsigned int flags)
> @@ -1183,6 +1195,7 @@ const struct file_operations cifs_dir_ops = {
>  	.copy_file_range = cifs_copy_file_range,
>  	.clone_file_range = cifs_clone_file_range,
>  	.llseek = generic_file_llseek,
> +	.fsync = cifs_dir_fsync,
>  };
>  
>  static void
> -- 
> 2.17.0
> 

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] cifs/smb3: directory sync should not return an error
  2018-05-10 16:04 [PATCH] cifs/smb3: directory sync should not return an error Steve French
  2018-05-10 16:37 ` Jeremy Allison
@ 2018-05-10 17:11 ` Pavel Shilovsky
  2018-05-10 18:48   ` Jeremy Allison
  2018-05-10 21:01 ` ronnie sahlberg
  2 siblings, 1 reply; 11+ messages in thread
From: Pavel Shilovsky @ 2018-05-10 17:11 UTC (permalink / raw)
  To: Steve French; +Cc: CIFS, linux-fsdevel, samba-technical

2018-05-10 9:04 GMT-07:00 Steve French via samba-technical
<samba-technical@lists.samba.org>:
> As with NFS, which ignores sync on directory handles,
> fsync on a directory handle is a noop for CIFS/SMB3.
> Do not return an error on it.  It breaks some database
> apps otherwise.

Reviewed-by: Pavel Shilovsky <pshilov@microsoft.com>

Best regards,
Pavel Shilovsky

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] cifs/smb3: directory sync should not return an error
  2018-05-10 17:11 ` Pavel Shilovsky
@ 2018-05-10 18:48   ` Jeremy Allison
  2018-05-10 20:28     ` Steve French
  0 siblings, 1 reply; 11+ messages in thread
From: Jeremy Allison @ 2018-05-10 18:48 UTC (permalink / raw)
  To: Pavel Shilovsky; +Cc: Steve French, linux-fsdevel, CIFS, samba-technical

On Thu, May 10, 2018 at 10:11:43AM -0700, Pavel Shilovsky via samba-technical wrote:
> 2018-05-10 9:04 GMT-07:00 Steve French via samba-technical
> <samba-technical@lists.samba.org>:
> > As with NFS, which ignores sync on directory handles,
> > fsync on a directory handle is a noop for CIFS/SMB3.
> > Do not return an error on it.  It breaks some database
> > apps otherwise.
> 
> Reviewed-by: Pavel Shilovsky <pshilov@microsoft.com>

NAK on this patch. It's due to a specific Samba server
bug, which I've just fixed.

Look at the man page for fsync() on directory handles
- in SMB2+ as well this is a useful thing for an
application to do.

The broken Samba server returns NT_STATUS_ACCESS_DENIED
here. What you need to do is test the popular servers
(Windows, NetApp, EMC, Samba, OSX) and see which of
them are broken (not Windows obviously) and if so
what errors they return.

Best case scenario it's just Samba that was broken,
so check for the specific NT_STATUS_ACCESS_DENIED
error and ignore, otherwise return the error to
the caller - they *NEED* it :-).

Jeremy.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] cifs/smb3: directory sync should not return an error
  2018-05-10 18:48   ` Jeremy Allison
@ 2018-05-10 20:28     ` Steve French
  2018-05-10 21:56       ` Steve French
  0 siblings, 1 reply; 11+ messages in thread
From: Steve French @ 2018-05-10 20:28 UTC (permalink / raw)
  To: Jeremy Allison; +Cc: Pavel Shilovsky, linux-fsdevel, CIFS, samba-technical

It wasn't sent to Samba - the error was returned by the VFS before it
comes to cifs.ko because we don't implement this call.    NFS
(correctly presumably) implements the syscall by ignoring it
(returning 0 - rather than the default which is an error), because
once an entry in the directory is created it is in the namespace, and
they are never cached on the client.

On Thu, May 10, 2018 at 1:48 PM, Jeremy Allison <jra@samba.org> wrote:
> On Thu, May 10, 2018 at 10:11:43AM -0700, Pavel Shilovsky via samba-technical wrote:
>> 2018-05-10 9:04 GMT-07:00 Steve French via samba-technical
>> <samba-technical@lists.samba.org>:
>> > As with NFS, which ignores sync on directory handles,
>> > fsync on a directory handle is a noop for CIFS/SMB3.
>> > Do not return an error on it.  It breaks some database
>> > apps otherwise.
>>
>> Reviewed-by: Pavel Shilovsky <pshilov@microsoft.com>
>
> NAK on this patch. It's due to a specific Samba server
> bug, which I've just fixed.
>
> Look at the man page for fsync() on directory handles
> - in SMB2+ as well this is a useful thing for an
> application to do.
>
> The broken Samba server returns NT_STATUS_ACCESS_DENIED
> here. What you need to do is test the popular servers
> (Windows, NetApp, EMC, Samba, OSX) and see which of
> them are broken (not Windows obviously) and if so
> what errors they return.
>
> Best case scenario it's just Samba that was broken,
> so check for the specific NT_STATUS_ACCESS_DENIED
> error and ignore, otherwise return the error to
> the caller - they *NEED* it :-).
>
> Jeremy.



-- 
Thanks,

Steve

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] cifs/smb3: directory sync should not return an error
  2018-05-10 16:04 [PATCH] cifs/smb3: directory sync should not return an error Steve French
  2018-05-10 16:37 ` Jeremy Allison
  2018-05-10 17:11 ` Pavel Shilovsky
@ 2018-05-10 21:01 ` ronnie sahlberg
  2 siblings, 0 replies; 11+ messages in thread
From: ronnie sahlberg @ 2018-05-10 21:01 UTC (permalink / raw)
  To: Steve French; +Cc: CIFS, linux-fsdevel, samba-technical

Reviewed-by: Ronnie Sahlberg <lsahlber@redhat.com>

On Fri, May 11, 2018 at 2:04 AM, Steve French via samba-technical
<samba-technical@lists.samba.org> wrote:
> As with NFS, which ignores sync on directory handles,
> fsync on a directory handle is a noop for CIFS/SMB3.
> Do not return an error on it.  It breaks some database
> apps otherwise.
>
>
>
> --
> Thanks,
>
> Steve

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] cifs/smb3: directory sync should not return an error
  2018-05-10 20:28     ` Steve French
@ 2018-05-10 21:56       ` Steve French
  2018-05-10 22:08         ` ronnie sahlberg
  0 siblings, 1 reply; 11+ messages in thread
From: Steve French @ 2018-05-10 21:56 UTC (permalink / raw)
  To: Jeremy Allison; +Cc: Pavel Shilovsky, linux-fsdevel, CIFS, samba-technical

checking various Linux file systems - looks like most of those I
checked end up with the default "EINVAL" so basically not a very
useful call to check the return code on - safer to ignore.   If others
prefer, I don't mind sending the call over the wire and ignoring the
return code - but presumably some server is going to error unusually
if we pass it over the wire and expect particularly return codes (and
thus break apps that check for rc==EINVAL or rc==0).

On Thu, May 10, 2018 at 3:28 PM, Steve French <smfrench@gmail.com> wrote:
> It wasn't sent to Samba - the error was returned by the VFS before it
> comes to cifs.ko because we don't implement this call.    NFS
> (correctly presumably) implements the syscall by ignoring it
> (returning 0 - rather than the default which is an error), because
> once an entry in the directory is created it is in the namespace, and
> they are never cached on the client.
>
> On Thu, May 10, 2018 at 1:48 PM, Jeremy Allison <jra@samba.org> wrote:
>> On Thu, May 10, 2018 at 10:11:43AM -0700, Pavel Shilovsky via samba-technical wrote:
>>> 2018-05-10 9:04 GMT-07:00 Steve French via samba-technical
>>> <samba-technical@lists.samba.org>:
>>> > As with NFS, which ignores sync on directory handles,
>>> > fsync on a directory handle is a noop for CIFS/SMB3.
>>> > Do not return an error on it.  It breaks some database
>>> > apps otherwise.
>>>
>>> Reviewed-by: Pavel Shilovsky <pshilov@microsoft.com>
>>
>> NAK on this patch. It's due to a specific Samba server
>> bug, which I've just fixed.
>>
>> Look at the man page for fsync() on directory handles
>> - in SMB2+ as well this is a useful thing for an
>> application to do.
>>
>> The broken Samba server returns NT_STATUS_ACCESS_DENIED
>> here. What you need to do is test the popular servers
>> (Windows, NetApp, EMC, Samba, OSX) and see which of
>> them are broken (not Windows obviously) and if so
>> what errors they return.
>>
>> Best case scenario it's just Samba that was broken,
>> so check for the specific NT_STATUS_ACCESS_DENIED
>> error and ignore, otherwise return the error to
>> the caller - they *NEED* it :-).
>>
>> Jeremy.
>
>
>
> --
> Thanks,
>
> Steve



-- 
Thanks,

Steve

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] cifs/smb3: directory sync should not return an error
  2018-05-10 21:56       ` Steve French
@ 2018-05-10 22:08         ` ronnie sahlberg
  2018-05-10 22:12           ` Jeremy Allison
  0 siblings, 1 reply; 11+ messages in thread
From: ronnie sahlberg @ 2018-05-10 22:08 UTC (permalink / raw)
  To: Steve French
  Cc: Jeremy Allison, linux-fsdevel, CIFS, Pavel Shilovsky, samba-technical

SMB2 FLUSH ?

MS-SMB2.pdf  is pretty clear that FLUSH can only be used on files or pipes.
If we start using it for directory handles we would need some
clarifications about this use in the spec.

I would wait until MS-SMB2 is updated before we start sending FLUSH on
directory handles.


On Fri, May 11, 2018 at 7:56 AM, Steve French via samba-technical
<samba-technical@lists.samba.org> wrote:
> checking various Linux file systems - looks like most of those I
> checked end up with the default "EINVAL" so basically not a very
> useful call to check the return code on - safer to ignore.   If others
> prefer, I don't mind sending the call over the wire and ignoring the
> return code - but presumably some server is going to error unusually
> if we pass it over the wire and expect particularly return codes (and
> thus break apps that check for rc==EINVAL or rc==0).
>
> On Thu, May 10, 2018 at 3:28 PM, Steve French <smfrench@gmail.com> wrote:
>> It wasn't sent to Samba - the error was returned by the VFS before it
>> comes to cifs.ko because we don't implement this call.    NFS
>> (correctly presumably) implements the syscall by ignoring it
>> (returning 0 - rather than the default which is an error), because
>> once an entry in the directory is created it is in the namespace, and
>> they are never cached on the client.
>>
>> On Thu, May 10, 2018 at 1:48 PM, Jeremy Allison <jra@samba.org> wrote:
>>> On Thu, May 10, 2018 at 10:11:43AM -0700, Pavel Shilovsky via samba-technical wrote:
>>>> 2018-05-10 9:04 GMT-07:00 Steve French via samba-technical
>>>> <samba-technical@lists.samba.org>:
>>>> > As with NFS, which ignores sync on directory handles,
>>>> > fsync on a directory handle is a noop for CIFS/SMB3.
>>>> > Do not return an error on it.  It breaks some database
>>>> > apps otherwise.
>>>>
>>>> Reviewed-by: Pavel Shilovsky <pshilov@microsoft.com>
>>>
>>> NAK on this patch. It's due to a specific Samba server
>>> bug, which I've just fixed.
>>>
>>> Look at the man page for fsync() on directory handles
>>> - in SMB2+ as well this is a useful thing for an
>>> application to do.
>>>
>>> The broken Samba server returns NT_STATUS_ACCESS_DENIED
>>> here. What you need to do is test the popular servers
>>> (Windows, NetApp, EMC, Samba, OSX) and see which of
>>> them are broken (not Windows obviously) and if so
>>> what errors they return.
>>>
>>> Best case scenario it's just Samba that was broken,
>>> so check for the specific NT_STATUS_ACCESS_DENIED
>>> error and ignore, otherwise return the error to
>>> the caller - they *NEED* it :-).
>>>
>>> Jeremy.
>>
>>
>>
>> --
>> Thanks,
>>
>> Steve
>
>
>
> --
> Thanks,
>
> Steve
>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] cifs/smb3: directory sync should not return an error
  2018-05-10 22:08         ` ronnie sahlberg
@ 2018-05-10 22:12           ` Jeremy Allison
  2018-05-10 22:25             ` Steve French
  0 siblings, 1 reply; 11+ messages in thread
From: Jeremy Allison @ 2018-05-10 22:12 UTC (permalink / raw)
  To: ronnie sahlberg
  Cc: Steve French, linux-fsdevel, CIFS, Pavel Shilovsky, samba-technical, jra

On Fri, May 11, 2018 at 08:08:46AM +1000, ronnie sahlberg wrote:
> SMB2 FLUSH ?
> 
> MS-SMB2.pdf  is pretty clear that FLUSH can only be used on files or pipes.
> If we start using it for directory handles we would need some
> clarifications about this use in the spec.

Yes. MS-SMB2 is also wrong :-).

I have test code that proves FLUSH works against any directory
handle opened with FILE_ADD|DIRECTORY_ADD access mask granted.

(Steve thought this might be special cased to just the root
directory handle on a share, this turns out not to be the
case - any directory handle with the required access works
OK).

> I would wait until MS-SMB2 is updated before we start sending FLUSH on
> directory handles.

We need to deal with the protocol as it really is,
not as the documentation would like it to be :-).

Jeremy.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] cifs/smb3: directory sync should not return an error
  2018-05-10 22:12           ` Jeremy Allison
@ 2018-05-10 22:25             ` Steve French
  2018-05-10 23:06               ` Jeremy Allison
  0 siblings, 1 reply; 11+ messages in thread
From: Steve French @ 2018-05-10 22:25 UTC (permalink / raw)
  To: Jeremy Allison
  Cc: ronnie sahlberg, linux-fsdevel, CIFS, Pavel Shilovsky, samba-technical

On Thu, May 10, 2018 at 5:12 PM, Jeremy Allison <jra@samba.org> wrote:
> On Fri, May 11, 2018 at 08:08:46AM +1000, ronnie sahlberg wrote:
>> SMB2 FLUSH ?
>>
>> MS-SMB2.pdf  is pretty clear that FLUSH can only be used on files or pipes.
>> If we start using it for directory handles we would need some
>> clarifications about this use in the spec.
>
> Yes. MS-SMB2 is also wrong :-).
>
> I have test code that proves FLUSH works against any directory
> handle opened with FILE_ADD|DIRECTORY_ADD access mask granted.
>
> (Steve thought this might be special cased to just the root
> directory handle on a share, this turns out not to be the
> case - any directory handle with the required access works
> OK).
>
>> I would wait until MS-SMB2 is updated before we start sending FLUSH on
>> directory handles.
>
> We need to deal with the protocol as it really is,
> not as the documentation would like it to be :-).

Current behavior seems to be that (for SMB2/SMB3 as with NFS)
servers are not expected to cache file creates.   If we send a flush over
the wire without a lot more testing we could break even more apps - unless
we simply send the request and ignore the return code which I would prefer
not to do until we get feedback from more servers and clarification from
MS-SMB2).  What we don't want to do is pass EINVAL back which breaks some.

Ronnie said it well:
" If/once ms-smb2.pdf is updated to describe the semantics for flush
on a directory, then we can think about using flush here. Not before.
Otherwise we just revert back to chasing implementation specific
behavior" (as we did with SMB1)

(so fix the current behavior - then think about whether we can safely
send this as a flush if there are any valid cases which MS-SMB2
exposes in the future).

-- 
Thanks,

Steve

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] cifs/smb3: directory sync should not return an error
  2018-05-10 22:25             ` Steve French
@ 2018-05-10 23:06               ` Jeremy Allison
  0 siblings, 0 replies; 11+ messages in thread
From: Jeremy Allison @ 2018-05-10 23:06 UTC (permalink / raw)
  To: Steve French
  Cc: ronnie sahlberg, linux-fsdevel, CIFS, Pavel Shilovsky, samba-technical

On Thu, May 10, 2018 at 05:25:55PM -0500, Steve French wrote:
> 
> Current behavior seems to be that (for SMB2/SMB3 as with NFS)
> servers are not expected to cache file creates.   If we send a flush over
> the wire without a lot more testing we could break even more apps - unless
> we simply send the request and ignore the return code which I would prefer
> not to do until we get feedback from more servers and clarification from
> MS-SMB2).  What we don't want to do is pass EINVAL back which breaks some.
> 
> Ronnie said it well:
> " If/once ms-smb2.pdf is updated to describe the semantics for flush
> on a directory, then we can think about using flush here. Not before.
> Otherwise we just revert back to chasing implementation specific
> behavior" (as we did with SMB1)
> 
> (so fix the current behavior - then think about whether we can safely
> send this as a flush if there are any valid cases which MS-SMB2
> exposes in the future).

In the meantime I'm going to fix the smbd server to act
the same way that Windows Does (TM). That's what real
clients expect :-).

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2018-05-10 23:06 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-10 16:04 [PATCH] cifs/smb3: directory sync should not return an error Steve French
2018-05-10 16:37 ` Jeremy Allison
2018-05-10 17:11 ` Pavel Shilovsky
2018-05-10 18:48   ` Jeremy Allison
2018-05-10 20:28     ` Steve French
2018-05-10 21:56       ` Steve French
2018-05-10 22:08         ` ronnie sahlberg
2018-05-10 22:12           ` Jeremy Allison
2018-05-10 22:25             ` Steve French
2018-05-10 23:06               ` Jeremy Allison
2018-05-10 21:01 ` ronnie sahlberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).