All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Howells <dhowells@redhat.com>
To: smfrench@gmail.com
Cc: dhowells@redhat.com, Shyam Prasad N <nspmangalore@gmail.com>,
	jlayton@kernel.org, linux-cifs@vger.kernel.org
Subject: Incorrect fallocate behaviour in cifs or samba?
Date: Thu, 13 Jan 2022 15:20:32 +0000	[thread overview]
Message-ID: <1856457.1642087232@warthog.procyon.org.uk> (raw)
In-Reply-To: <1828480.1642079920@warthog.procyon.org.uk>

David Howells <dhowells@redhat.com> wrote:

> If I do the following:
> 
> 	mount //carina/test /xfstest.test -o user=shares,pass=foobar,noperm,vers=3.0,mfsymlinks,actimeo=0
> 	/usr/sbin/xfs_io -f -t \
> 		-c "pwrite -S 0x41 0 4096"
> 		-c "pwrite -S 0x42 4096 4096"
> 		-c "fzero 0 4096" \
> 		-c "pread 0 8192" \
> 		/xfstest.test/008.7067
> ...
>    31 0.321638749  192.168.6.2 -> 192.168.6.1  SMB2 206 Ioctl Request FSCTL_SET_ZERO_DATA File: 008.7067

So what I see is that Samba does:

	fallocate(24, FALLOC_FL_KEEP_SIZE|FALLOC_FL_PUNCH_HOLE, 0, 4096) = 0

for this... but that's not what cifs was asked to do.  Should Samba be using
FALLOC_FL_ZERO_RANGE instead?

Also cifs wasn't given FALLOC_FL_KEEP_SIZE, so the caller expected the file to
be extended - smb3_zero_range(), however, doesn't seem necessarily to get this
right.  It seems to allow for KEEP_SIZE not being set by calling
SMB2_set_eof() - but only if the range ends beyond the *local* i_size (which
the server doesn't know about yet).

However, we did two pwrites first, which moved the local i_size over.  This
means the server's EOF isn't extended - probably correctly, since we haven't
saved the data, but the subsequent reads then fail.

In this case, I wonder if the right thing to do is one of the following
options:

 (1) Flush the pagecache before doing proceeding with the fallocate.

 (2) Modify the local pagecache and don't talk to the server at all unless
     there are gaps in the pagecache.

 (3) Keep separate track of where we think the server's EOF is and skip any
     read that's beyond that.

 (4) Treat a read ending in EOF as a read of blank data if it's below the
     local EOF.  I guess that's what we do now.

David


  reply	other threads:[~2022-01-13 15:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-13 13:18 cifs fallocate doesn't flush writes? David Howells
2022-01-13 15:20 ` David Howells [this message]
2022-01-13 17:43   ` Incorrect fallocate behaviour in cifs or samba? Jeremy Allison
2022-01-13 18:16     ` David Disseldorp
2022-01-13 18:22       ` Jeremy Allison

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1856457.1642087232@warthog.procyon.org.uk \
    --to=dhowells@redhat.com \
    --cc=jlayton@kernel.org \
    --cc=linux-cifs@vger.kernel.org \
    --cc=nspmangalore@gmail.com \
    --cc=smfrench@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.