linux-cifs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* RE: [PATCH] cifs: only write 64kb at a time when fallocating a small region of a file
       [not found] ` <014c01d77dd3$57add320$07097960$@samsung.com>
@ 2021-07-21  7:21   ` Namjae Jeon
       [not found]     ` <CAGvGhF55Tq-sLUtKBn+QX6kWrL9dDzKkXFKdQ==gz3s=RkySKQ@mail.gmail.com>
  0 siblings, 1 reply; 8+ messages in thread
From: Namjae Jeon @ 2021-07-21  7:21 UTC (permalink / raw)
  To: 'Ronnie Sahlberg'; +Cc: linux-cifs

Hi Ronnie,

> We only allow sending single credit writes through the SMB2_write() synchronous api so split this into
> smaller chunks.
> 
> Fixes: 966a3cb7c7db ("cifs: improve fallocate emulation")
> 
> Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
> ---
>  fs/cifs/smb2ops.c | 31 +++++++++++++++++++------------
>  1 file changed, 19 insertions(+), 12 deletions(-)
> 
> diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index ba3c58e1f725..7fefa100887b 100644
> --- a/fs/cifs/smb2ops.c
> +++ b/fs/cifs/smb2ops.c
> @@ -3617,7 +3617,7 @@ static int smb3_simple_fallocate_write_range(unsigned int xid,
>                                              char *buf)  {
>         struct cifs_io_parms io_parms = {0};
> -       int nbytes;
> +       int rc, nbytes;
>         struct kvec iov[2];
> 
>         io_parms.netfid = cfile->fid.netfid; @@ -3625,13 +3625,25 @@ static int
> smb3_simple_fallocate_write_range(unsigned int xid,
>         io_parms.tcon = tcon;
>         io_parms.persistent_fid = cfile->fid.persistent_fid;
>         io_parms.volatile_fid = cfile->fid.volatile_fid;
> -       io_parms.offset = off;
> -       io_parms.length = len;
> 
> -       /* iov[0] is reserved for smb header */
> -       iov[1].iov_base = buf;
> -       iov[1].iov_len = io_parms.length;
> -       return SMB2_write(xid, &io_parms, &nbytes, iov, 1);
> +       while (len) {
> +               io_parms.offset = off;
> +               io_parms.length = len;
> +               if (io_parms.length > 65536)
> +                       io_parms.length = 65536;
Minor nit, We can probably use a defined macro, SMB2_MAX_BUFFER_SIZE.

> +               /* iov[0] is reserved for smb header */
> +               iov[1].iov_base = buf;
> +               iov[1].iov_len = io_parms.length;
> +               rc = SMB2_write(xid, &io_parms, &nbytes, iov, 1);
> +               if (rc)
> +                       break;
> +               if (nbytes > len)
> +                       return -EINVAL;
> +               buf += nbytes;
> +               off += nbytes;
> +               len -= nbytes;
> +       }
> +       return rc;
>  }
> 
>  static int smb3_simple_fallocate_range(unsigned int xid, @@ -3655,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;
Is there any reason to remove this code ?
Because xfstests generic/071 test failed against ksmbd without this code.

generic/071 files ... - output mismatch (see /home/linkinjeon/xfstests-ksmbd/results//generic/071.out.bad)
    --- tests/generic/071.out   2020-02-05 09:07:30.000000000 +0900
    +++ /home/linkinjeon/xfstests/xfstests-ksmbd/results//generic/071.out.bad 2021-07-21 15:32:18.001170684 +0900
    @@ -6,4 +6,4 @@
     *
     1000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
     *
    -2000000
    +4000000
    ...
    (Run 'diff -u /home/linkinjeon/xfstests-ksmbd/tests/generic/071.out /home/linkinjeon/xfstests-ksmbd/results//generic/071.out.bad'  to see the entire diff)
Ran: generic/071
Failures: generic/071
Failed 1 of 1 tests

Thanks!
> 
>         buf = kzalloc(1024 * 1024, GFP_KERNEL);
>         if (buf == NULL) {
> --
> 2.30.2



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

* RE: [PATCH] cifs: only write 64kb at a time when fallocating a small region of a file
       [not found]     ` <CAGvGhF55Tq-sLUtKBn+QX6kWrL9dDzKkXFKdQ==gz3s=RkySKQ@mail.gmail.com>
@ 2021-07-22  6:54       ` Namjae Jeon
  2021-07-22  7:17         ` ronnie sahlberg
  0 siblings, 1 reply; 8+ messages in thread
From: Namjae Jeon @ 2021-07-22  6:54 UTC (permalink / raw)
  To: 'Leif Sahlberg'; +Cc: linux-cifs

> This code is actually bogus and does the opposite of what the comment says.
> If out_data_len is 0 then that means that the entire region is unallocated and then we should not
> bail out but proceed and allocate the hole.

> generic/071 works against a windows server for me.


> If it fails with this code removed it might mean that generic/071 never worked with cifs.ko correctly.

generic/071 create preallocated extent by calling fallocate with keep size flags.
It means the file size should not be increased.
But if (out_buf_len == 0) check is removed, 1MB write is performed using SMB2_write loop().
It means the file size becomes 1MB.

And then, generic/071 call again fallocate(0, 512K) which mean file size should be 512K.
but SMB2_set_eof() in cifs is not called due to the code below(->i_size is bigger than off + len),
So 071 test failed as file size remains 1MB.

        /*
         * Extending the file
         */
        if ((keep_size == false) && i_size_read(inode) < off + len) {
                rc = inode_newsize_ok(inode, off + len);
                if (rc)
                        goto out;

                if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0)
                        smb2_set_sparse(xid, tcon, cfile, inode, false);

                eof = cpu_to_le64(off + len);
                rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
                                  cfile->fid.volatile_fid, cfile->pid, &eof);
                if (rc == 0) {
                        cifsi->server_eof = off + len;
                        cifs_setsize(inode, off + len);
                        cifs_truncate_page(inode->i_mapping, inode->i_size);
                        truncate_setsize(inode, off + len);
                }
                goto out;
        }


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

* Re: [PATCH] cifs: only write 64kb at a time when fallocating a small region of a file
  2021-07-22  6:54       ` Namjae Jeon
@ 2021-07-22  7:17         ` ronnie sahlberg
  2021-07-22  7:22           ` Namjae Jeon
  2021-07-22 16:44           ` Steve French
  0 siblings, 2 replies; 8+ messages in thread
From: ronnie sahlberg @ 2021-07-22  7:17 UTC (permalink / raw)
  To: Namjae Jeon; +Cc: Leif Sahlberg, linux-cifs

Yes, ofcourse.

Steve, can you revert that deletion in the patch?

On Thu, Jul 22, 2021 at 4:55 PM Namjae Jeon <namjae.jeon@samsung.com> wrote:
>
> > This code is actually bogus and does the opposite of what the comment says.
> > If out_data_len is 0 then that means that the entire region is unallocated and then we should not
> > bail out but proceed and allocate the hole.
>
> > generic/071 works against a windows server for me.
>
>
> > If it fails with this code removed it might mean that generic/071 never worked with cifs.ko correctly.
>
> generic/071 create preallocated extent by calling fallocate with keep size flags.
> It means the file size should not be increased.
> But if (out_buf_len == 0) check is removed, 1MB write is performed using SMB2_write loop().
> It means the file size becomes 1MB.
>
> And then, generic/071 call again fallocate(0, 512K) which mean file size should be 512K.
> but SMB2_set_eof() in cifs is not called due to the code below(->i_size is bigger than off + len),
> So 071 test failed as file size remains 1MB.
>
>         /*
>          * Extending the file
>          */
>         if ((keep_size == false) && i_size_read(inode) < off + len) {
>                 rc = inode_newsize_ok(inode, off + len);
>                 if (rc)
>                         goto out;
>
>                 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0)
>                         smb2_set_sparse(xid, tcon, cfile, inode, false);
>
>                 eof = cpu_to_le64(off + len);
>                 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
>                                   cfile->fid.volatile_fid, cfile->pid, &eof);
>                 if (rc == 0) {
>                         cifsi->server_eof = off + len;
>                         cifs_setsize(inode, off + len);
>                         cifs_truncate_page(inode->i_mapping, inode->i_size);
>                         truncate_setsize(inode, off + len);
>                 }
>                 goto out;
>         }
>

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

* RE: [PATCH] cifs: only write 64kb at a time when fallocating a small region of a file
  2021-07-22  7:17         ` ronnie sahlberg
@ 2021-07-22  7:22           ` Namjae Jeon
  2021-07-22 16:44           ` Steve French
  1 sibling, 0 replies; 8+ messages in thread
From: Namjae Jeon @ 2021-07-22  7:22 UTC (permalink / raw)
  To: 'ronnie sahlberg'; +Cc: 'Leif Sahlberg', 'linux-cifs'

> Yes, ofcourse.
Thank you!

> 
> Steve, can you revert that deletion in the patch?
> 
> On Thu, Jul 22, 2021 at 4:55 PM Namjae Jeon <namjae.jeon@samsung.com> wrote:
> >
> > > This code is actually bogus and does the opposite of what the comment says.
> > > If out_data_len is 0 then that means that the entire region is
> > > unallocated and then we should not bail out but proceed and allocate the hole.
> >
> > > generic/071 works against a windows server for me.
> >
> >
> > > If it fails with this code removed it might mean that generic/071 never worked with cifs.ko
> correctly.
> >
> > generic/071 create preallocated extent by calling fallocate with keep size flags.
> > It means the file size should not be increased.
> > But if (out_buf_len == 0) check is removed, 1MB write is performed using SMB2_write loop().
> > It means the file size becomes 1MB.
> >
> > And then, generic/071 call again fallocate(0, 512K) which mean file size should be 512K.
> > but SMB2_set_eof() in cifs is not called due to the code
> > below(->i_size is bigger than off + len), So 071 test failed as file size remains 1MB.
> >
> >         /*
> >          * Extending the file
> >          */
> >         if ((keep_size == false) && i_size_read(inode) < off + len) {
> >                 rc = inode_newsize_ok(inode, off + len);
> >                 if (rc)
> >                         goto out;
> >
> >                 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0)
> >                         smb2_set_sparse(xid, tcon, cfile, inode,
> > false);
> >
> >                 eof = cpu_to_le64(off + len);
> >                 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
> >                                   cfile->fid.volatile_fid, cfile->pid, &eof);
> >                 if (rc == 0) {
> >                         cifsi->server_eof = off + len;
> >                         cifs_setsize(inode, off + len);
> >                         cifs_truncate_page(inode->i_mapping, inode->i_size);
> >                         truncate_setsize(inode, off + len);
> >                 }
> >                 goto out;
> >         }
> >


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

* Re: [PATCH] cifs: only write 64kb at a time when fallocating a small region of a file
  2021-07-22  7:17         ` ronnie sahlberg
  2021-07-22  7:22           ` Namjae Jeon
@ 2021-07-22 16:44           ` Steve French
  1 sibling, 0 replies; 8+ messages in thread
From: Steve French @ 2021-07-22 16:44 UTC (permalink / raw)
  To: ronnie sahlberg; +Cc: Namjae Jeon, Leif Sahlberg, linux-cifs

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

Removed the deletion from the patch, and added Reported-by: Namjae ...
and pushed to cifs-2.6.git for-next

On Thu, Jul 22, 2021 at 2:19 AM ronnie sahlberg
<ronniesahlberg@gmail.com> wrote:
>
> Yes, ofcourse.
>
> Steve, can you revert that deletion in the patch?
>
> On Thu, Jul 22, 2021 at 4:55 PM Namjae Jeon <namjae.jeon@samsung.com> wrote:
> >
> > > This code is actually bogus and does the opposite of what the comment says.
> > > If out_data_len is 0 then that means that the entire region is unallocated and then we should not
> > > bail out but proceed and allocate the hole.
> >
> > > generic/071 works against a windows server for me.
> >
> >
> > > If it fails with this code removed it might mean that generic/071 never worked with cifs.ko correctly.
> >
> > generic/071 create preallocated extent by calling fallocate with keep size flags.
> > It means the file size should not be increased.
> > But if (out_buf_len == 0) check is removed, 1MB write is performed using SMB2_write loop().
> > It means the file size becomes 1MB.
> >
> > And then, generic/071 call again fallocate(0, 512K) which mean file size should be 512K.
> > but SMB2_set_eof() in cifs is not called due to the code below(->i_size is bigger than off + len),
> > So 071 test failed as file size remains 1MB.
> >
> >         /*
> >          * Extending the file
> >          */
> >         if ((keep_size == false) && i_size_read(inode) < off + len) {
> >                 rc = inode_newsize_ok(inode, off + len);
> >                 if (rc)
> >                         goto out;
> >
> >                 if ((cifsi->cifsAttrs & FILE_ATTRIBUTE_SPARSE_FILE) == 0)
> >                         smb2_set_sparse(xid, tcon, cfile, inode, false);
> >
> >                 eof = cpu_to_le64(off + len);
> >                 rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
> >                                   cfile->fid.volatile_fid, cfile->pid, &eof);
> >                 if (rc == 0) {
> >                         cifsi->server_eof = off + len;
> >                         cifs_setsize(inode, off + len);
> >                         cifs_truncate_page(inode->i_mapping, inode->i_size);
> >                         truncate_setsize(inode, off + len);
> >                 }
> >                 goto out;
> >         }
> >



-- 
Thanks,

Steve

[-- Attachment #2: 0001-cifs-only-write-64kb-at-a-time-when-fallocating-a-sm.patch --]
[-- Type: text/x-patch, Size: 2028 bytes --]

From 2485bd7557a7edb4520b4072af464f0a08c8efe0 Mon Sep 17 00:00:00 2001
From: Ronnie Sahlberg <lsahlber@redhat.com>
Date: Thu, 22 Jul 2021 14:53:32 +1000
Subject: [PATCH 1/2] cifs: only write 64kb at a time when fallocating a small
 region of a file

We only allow sending single credit writes through the SMB2_write() synchronous
api so split this into smaller chunks.

Fixes: 966a3cb7c7db ("cifs: improve fallocate emulation")

Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
Reported-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
---
 fs/cifs/smb2ops.c | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
index ba3c58e1f725..5cefb5972396 100644
--- a/fs/cifs/smb2ops.c
+++ b/fs/cifs/smb2ops.c
@@ -3617,7 +3617,7 @@ static int smb3_simple_fallocate_write_range(unsigned int xid,
 					     char *buf)
 {
 	struct cifs_io_parms io_parms = {0};
-	int nbytes;
+	int rc, nbytes;
 	struct kvec iov[2];
 
 	io_parms.netfid = cfile->fid.netfid;
@@ -3625,13 +3625,25 @@ static int smb3_simple_fallocate_write_range(unsigned int xid,
 	io_parms.tcon = tcon;
 	io_parms.persistent_fid = cfile->fid.persistent_fid;
 	io_parms.volatile_fid = cfile->fid.volatile_fid;
-	io_parms.offset = off;
-	io_parms.length = len;
 
-	/* iov[0] is reserved for smb header */
-	iov[1].iov_base = buf;
-	iov[1].iov_len = io_parms.length;
-	return SMB2_write(xid, &io_parms, &nbytes, iov, 1);
+	while (len) {
+		io_parms.offset = off;
+		io_parms.length = len;
+		if (io_parms.length > SMB2_MAX_BUFFER_SIZE)
+			io_parms.length = SMB2_MAX_BUFFER_SIZE;
+		/* iov[0] is reserved for smb header */
+		iov[1].iov_base = buf;
+		iov[1].iov_len = io_parms.length;
+		rc = SMB2_write(xid, &io_parms, &nbytes, iov, 1);
+		if (rc)
+			break;
+		if (nbytes > len)
+			return -EINVAL;
+		buf += nbytes;
+		off += nbytes;
+		len -= nbytes;
+	}
+	return rc;
 }
 
 static int smb3_simple_fallocate_range(unsigned int xid,
-- 
2.30.2


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

* [PATCH] cifs: only write 64kb at a time when fallocating a small region of a file
@ 2021-07-22  4:53 Ronnie Sahlberg
  0 siblings, 0 replies; 8+ messages in thread
From: Ronnie Sahlberg @ 2021-07-22  4:53 UTC (permalink / raw)
  To: linux-cifs; +Cc: Steve French

We only allow sending single credit writes through the SMB2_write() synchronous
api so split this into smaller chunks.

Fixes: 966a3cb7c7db ("cifs: improve fallocate emulation")

Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
---
 fs/cifs/smb2ops.c | 31 +++++++++++++++++++------------
 1 file changed, 19 insertions(+), 12 deletions(-)

diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
index ba3c58e1f725..36ce91893a82 100644
--- a/fs/cifs/smb2ops.c
+++ b/fs/cifs/smb2ops.c
@@ -3617,7 +3617,7 @@ static int smb3_simple_fallocate_write_range(unsigned int xid,
 					     char *buf)
 {
 	struct cifs_io_parms io_parms = {0};
-	int nbytes;
+	int rc, nbytes;
 	struct kvec iov[2];
 
 	io_parms.netfid = cfile->fid.netfid;
@@ -3625,13 +3625,25 @@ static int smb3_simple_fallocate_write_range(unsigned int xid,
 	io_parms.tcon = tcon;
 	io_parms.persistent_fid = cfile->fid.persistent_fid;
 	io_parms.volatile_fid = cfile->fid.volatile_fid;
-	io_parms.offset = off;
-	io_parms.length = len;
 
-	/* iov[0] is reserved for smb header */
-	iov[1].iov_base = buf;
-	iov[1].iov_len = io_parms.length;
-	return SMB2_write(xid, &io_parms, &nbytes, iov, 1);
+	while (len) {
+		io_parms.offset = off;
+		io_parms.length = len;
+		if (io_parms.length > SMB2_MAX_BUFFER_SIZE)
+			io_parms.length = SMB2_MAX_BUFFER_SIZE;
+		/* iov[0] is reserved for smb header */
+		iov[1].iov_base = buf;
+		iov[1].iov_len = io_parms.length;
+		rc = SMB2_write(xid, &io_parms, &nbytes, iov, 1);
+		if (rc)
+			break;
+		if (nbytes > len)
+			return -EINVAL;
+		buf += nbytes;
+		off += nbytes;
+		len -= nbytes;
+	}
+	return rc;
 }
 
 static int smb3_simple_fallocate_range(unsigned int xid,
@@ -3655,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) {
-- 
2.30.2


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

* [PATCH] cifs: only write 64kb at a time when fallocating a small region of a file
@ 2021-07-21  0:50 Ronnie Sahlberg
  0 siblings, 0 replies; 8+ messages in thread
From: Ronnie Sahlberg @ 2021-07-21  0:50 UTC (permalink / raw)
  To: linux-cifs; +Cc: Steve French

We only allow sending single credit writes through the SMB2_write() synchronous
api so split this into smaller chunks.

Fixes: 966a3cb7c7db ("cifs: improve fallocate emulation")

Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
---
 fs/cifs/smb2ops.c | 31 +++++++++++++++++++------------
 1 file changed, 19 insertions(+), 12 deletions(-)

diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
index ba3c58e1f725..7fefa100887b 100644
--- a/fs/cifs/smb2ops.c
+++ b/fs/cifs/smb2ops.c
@@ -3617,7 +3617,7 @@ static int smb3_simple_fallocate_write_range(unsigned int xid,
 					     char *buf)
 {
 	struct cifs_io_parms io_parms = {0};
-	int nbytes;
+	int rc, nbytes;
 	struct kvec iov[2];
 
 	io_parms.netfid = cfile->fid.netfid;
@@ -3625,13 +3625,25 @@ static int smb3_simple_fallocate_write_range(unsigned int xid,
 	io_parms.tcon = tcon;
 	io_parms.persistent_fid = cfile->fid.persistent_fid;
 	io_parms.volatile_fid = cfile->fid.volatile_fid;
-	io_parms.offset = off;
-	io_parms.length = len;
 
-	/* iov[0] is reserved for smb header */
-	iov[1].iov_base = buf;
-	iov[1].iov_len = io_parms.length;
-	return SMB2_write(xid, &io_parms, &nbytes, iov, 1);
+	while (len) {
+		io_parms.offset = off;
+		io_parms.length = len;
+		if (io_parms.length > 65536)
+			io_parms.length = 65536;
+		/* iov[0] is reserved for smb header */
+		iov[1].iov_base = buf;
+		iov[1].iov_len = io_parms.length;
+		rc = SMB2_write(xid, &io_parms, &nbytes, iov, 1);
+		if (rc)
+			break;
+		if (nbytes > len)
+			return -EINVAL;
+		buf += nbytes;
+		off += nbytes;
+		len -= nbytes;
+	}
+	return rc;
 }
 
 static int smb3_simple_fallocate_range(unsigned int xid,
@@ -3655,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) {
-- 
2.30.2


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

* [PATCH] cifs: only write 64kb at a time when fallocating a small region of a file
@ 2021-07-21  0:49 Ronnie Sahlberg
  0 siblings, 0 replies; 8+ messages in thread
From: Ronnie Sahlberg @ 2021-07-21  0:49 UTC (permalink / raw)
  To: linux-cifs; +Cc: Steve French

We only allow sending single credit reads through the SMB2_write() synchronous api
so split this into smaller chunks.

Fixes: 966a3cb7c7db ("cifs: improve fallocate emulation")

Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
---
 fs/cifs/smb2ops.c | 31 +++++++++++++++++++------------
 1 file changed, 19 insertions(+), 12 deletions(-)

diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
index ba3c58e1f725..7fefa100887b 100644
--- a/fs/cifs/smb2ops.c
+++ b/fs/cifs/smb2ops.c
@@ -3617,7 +3617,7 @@ static int smb3_simple_fallocate_write_range(unsigned int xid,
 					     char *buf)
 {
 	struct cifs_io_parms io_parms = {0};
-	int nbytes;
+	int rc, nbytes;
 	struct kvec iov[2];
 
 	io_parms.netfid = cfile->fid.netfid;
@@ -3625,13 +3625,25 @@ static int smb3_simple_fallocate_write_range(unsigned int xid,
 	io_parms.tcon = tcon;
 	io_parms.persistent_fid = cfile->fid.persistent_fid;
 	io_parms.volatile_fid = cfile->fid.volatile_fid;
-	io_parms.offset = off;
-	io_parms.length = len;
 
-	/* iov[0] is reserved for smb header */
-	iov[1].iov_base = buf;
-	iov[1].iov_len = io_parms.length;
-	return SMB2_write(xid, &io_parms, &nbytes, iov, 1);
+	while (len) {
+		io_parms.offset = off;
+		io_parms.length = len;
+		if (io_parms.length > 65536)
+			io_parms.length = 65536;
+		/* iov[0] is reserved for smb header */
+		iov[1].iov_base = buf;
+		iov[1].iov_len = io_parms.length;
+		rc = SMB2_write(xid, &io_parms, &nbytes, iov, 1);
+		if (rc)
+			break;
+		if (nbytes > len)
+			return -EINVAL;
+		buf += nbytes;
+		off += nbytes;
+		len -= nbytes;
+	}
+	return rc;
 }
 
 static int smb3_simple_fallocate_range(unsigned int xid,
@@ -3655,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) {
-- 
2.30.2


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

end of thread, other threads:[~2021-07-22 16:50 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20210721015429epcas1p4654c2b9348101aa7967bfe60d1d8da71@epcas1p4.samsung.com>
     [not found] ` <014c01d77dd3$57add320$07097960$@samsung.com>
2021-07-21  7:21   ` [PATCH] cifs: only write 64kb at a time when fallocating a small region of a file Namjae Jeon
     [not found]     ` <CAGvGhF55Tq-sLUtKBn+QX6kWrL9dDzKkXFKdQ==gz3s=RkySKQ@mail.gmail.com>
2021-07-22  6:54       ` Namjae Jeon
2021-07-22  7:17         ` ronnie sahlberg
2021-07-22  7:22           ` Namjae Jeon
2021-07-22 16:44           ` Steve French
2021-07-22  4:53 Ronnie Sahlberg
  -- strict thread matches above, loose matches on Subject: below --
2021-07-21  0:50 Ronnie Sahlberg
2021-07-21  0:49 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).