linux-cifs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steve French <smfrench@gmail.com>
To: Ronnie Sahlberg <lsahlber@redhat.com>
Cc: linux-cifs <linux-cifs@vger.kernel.org>
Subject: Re: [PATCH] cifs: fix fallocate when trying to allocate a hole.
Date: Thu, 22 Jul 2021 21:25:49 -0500	[thread overview]
Message-ID: <CAH2r5mvQbdcCpHW+g+p54Sjdj+DP-pwtbsJ=o7KxFaRweo-Yew@mail.gmail.com> (raw)
In-Reply-To: <20210723012124.3405007-1-lsahlber@redhat.com>

With the minor fix to change the rc from EFBIG to 0 to address the
xfstest 071 failure, tentatively merged into cifs-2.6.git for-next
pending more testing

On Thu, Jul 22, 2021 at 8:21 PM Ronnie Sahlberg <lsahlber@redhat.com> wrote:
>
> Remove the conditional checking for out_data_len and skipping the fallocate
> if it is 0. This is wrong will actually change any legitimate the fallocate
> where the entire region is unallocated into a no-op.
>
> Additionally, before allocating the range, if FALLOC_FL_KEEP_SIZE is set then
> we need to clamp the length of the fallocate region as to not extend the size of the file.
>
> Fixes: 966a3cb7c7db ("cifs: improve fallocate emulation")
> Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
> ---
>  fs/cifs/smb2ops.c | 23 ++++++++++++++++++-----
>  1 file changed, 18 insertions(+), 5 deletions(-)
>
> diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
> index 5cefb5972396..238717654e46 100644
> --- a/fs/cifs/smb2ops.c
> +++ b/fs/cifs/smb2ops.c
> @@ -3667,11 +3667,6 @@ static int smb3_simple_fallocate_range(unsigned int xid,
>                         (char **)&out_data, &out_data_len);
>         if (rc)
>                 goto out;
> -       /*
> -        * It is already all allocated
> -        */
> -       if (out_data_len == 0)
> -               goto out;
>
>         buf = kzalloc(1024 * 1024, GFP_KERNEL);
>         if (buf == NULL) {
> @@ -3794,6 +3789,24 @@ static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
>                 goto out;
>         }
>
> +       if (keep_size == true) {
> +               /*
> +                * We can not preallocate pages beyond the end of the file
> +                * in SMB2.
> +                */
> +               if (off >= i_size_read(inode)) {
> +                       rc = -EFBIG;
> +                       goto out;
> +               }
> +               /*
> +                * For fallocates that are partially beyond the end of file,
> +                * clamp len so we only fallocate up to the end of file.
> +                */
> +               if (off + len > i_size_read(inode)) {
> +                       len = i_size_read(inode) - off;
> +               }
> +       }
> +
>         if ((keep_size == true) || (i_size_read(inode) >= off + len)) {
>                 /*
>                  * At this point, we are trying to fallocate an internal
> --
> 2.30.2
>


-- 
Thanks,

Steve

      reply	other threads:[~2021-07-23  2:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-23  1:21 [PATCH] cifs: fix fallocate when trying to allocate a hole Ronnie Sahlberg
2021-07-23  2:25 ` Steve French [this message]

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='CAH2r5mvQbdcCpHW+g+p54Sjdj+DP-pwtbsJ=o7KxFaRweo-Yew@mail.gmail.com' \
    --to=smfrench@gmail.com \
    --cc=linux-cifs@vger.kernel.org \
    --cc=lsahlber@redhat.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 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).