All of lore.kernel.org
 help / color / mirror / Atom feed
* [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; 9+ 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] 9+ 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; 9+ 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] 9+ messages in thread
* Re: [PATCH] cifs: only write 64kb at a time when fallocating a small region of a file
@ 2021-07-21  3:15 kernel test robot
  0 siblings, 0 replies; 9+ messages in thread
From: kernel test robot @ 2021-07-21  3:15 UTC (permalink / raw)
  To: kbuild

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

CC: kbuild-all(a)lists.01.org
In-Reply-To: <20210721005015.3329781-1-lsahlber@redhat.com>
References: <20210721005015.3329781-1-lsahlber@redhat.com>
TO: Ronnie Sahlberg <lsahlber@redhat.com>
TO: "linux-cifs" <linux-cifs@vger.kernel.org>
CC: Steve French <smfrench@gmail.com>

Hi Ronnie,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on v5.14-rc2]
[also build test WARNING on next-20210720]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Ronnie-Sahlberg/cifs-only-write-64kb-at-a-time-when-fallocating-a-small-region-of-a-file/20210721-085112
base:    2734d6c1b1a089fb593ef6a23d4b70903526fe0c
:::::: branch date: 2 hours ago
:::::: commit date: 2 hours ago
config: i386-randconfig-m021-20210720 (attached as .config)
compiler: gcc-10 (Ubuntu 10.3.0-1ubuntu1~20.04) 10.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

smatch warnings:
fs/cifs/smb2ops.c:3646 smb3_simple_fallocate_write_range() error: uninitialized symbol 'rc'.

vim +/rc +3646 fs/cifs/smb2ops.c

31742c5a331766 Steve French    2014-08-17  3612  
966a3cb7c7db78 Ronnie Sahlberg 2021-06-03  3613  static int smb3_simple_fallocate_write_range(unsigned int xid,
966a3cb7c7db78 Ronnie Sahlberg 2021-06-03  3614  					     struct cifs_tcon *tcon,
966a3cb7c7db78 Ronnie Sahlberg 2021-06-03  3615  					     struct cifsFileInfo *cfile,
966a3cb7c7db78 Ronnie Sahlberg 2021-06-03  3616  					     loff_t off, loff_t len,
966a3cb7c7db78 Ronnie Sahlberg 2021-06-03  3617  					     char *buf)
966a3cb7c7db78 Ronnie Sahlberg 2021-06-03  3618  {
966a3cb7c7db78 Ronnie Sahlberg 2021-06-03  3619  	struct cifs_io_parms io_parms = {0};
f5db424b3e14aa Ronnie Sahlberg 2021-07-21  3620  	int rc, nbytes;
966a3cb7c7db78 Ronnie Sahlberg 2021-06-03  3621  	struct kvec iov[2];
966a3cb7c7db78 Ronnie Sahlberg 2021-06-03  3622  
966a3cb7c7db78 Ronnie Sahlberg 2021-06-03  3623  	io_parms.netfid = cfile->fid.netfid;
966a3cb7c7db78 Ronnie Sahlberg 2021-06-03  3624  	io_parms.pid = current->tgid;
966a3cb7c7db78 Ronnie Sahlberg 2021-06-03  3625  	io_parms.tcon = tcon;
966a3cb7c7db78 Ronnie Sahlberg 2021-06-03  3626  	io_parms.persistent_fid = cfile->fid.persistent_fid;
966a3cb7c7db78 Ronnie Sahlberg 2021-06-03  3627  	io_parms.volatile_fid = cfile->fid.volatile_fid;
f5db424b3e14aa Ronnie Sahlberg 2021-07-21  3628  
f5db424b3e14aa Ronnie Sahlberg 2021-07-21  3629  	while (len) {
966a3cb7c7db78 Ronnie Sahlberg 2021-06-03  3630  		io_parms.offset = off;
966a3cb7c7db78 Ronnie Sahlberg 2021-06-03  3631  		io_parms.length = len;
f5db424b3e14aa Ronnie Sahlberg 2021-07-21  3632  		if (io_parms.length > 65536)
f5db424b3e14aa Ronnie Sahlberg 2021-07-21  3633  			io_parms.length = 65536;
966a3cb7c7db78 Ronnie Sahlberg 2021-06-03  3634  		/* iov[0] is reserved for smb header */
966a3cb7c7db78 Ronnie Sahlberg 2021-06-03  3635  		iov[1].iov_base = buf;
966a3cb7c7db78 Ronnie Sahlberg 2021-06-03  3636  		iov[1].iov_len = io_parms.length;
f5db424b3e14aa Ronnie Sahlberg 2021-07-21  3637  		rc = SMB2_write(xid, &io_parms, &nbytes, iov, 1);
f5db424b3e14aa Ronnie Sahlberg 2021-07-21  3638  		if (rc)
f5db424b3e14aa Ronnie Sahlberg 2021-07-21  3639  			break;
f5db424b3e14aa Ronnie Sahlberg 2021-07-21  3640  		if (nbytes > len)
f5db424b3e14aa Ronnie Sahlberg 2021-07-21  3641  			return -EINVAL;
f5db424b3e14aa Ronnie Sahlberg 2021-07-21  3642  		buf += nbytes;
f5db424b3e14aa Ronnie Sahlberg 2021-07-21  3643  		off += nbytes;
f5db424b3e14aa Ronnie Sahlberg 2021-07-21  3644  		len -= nbytes;
f5db424b3e14aa Ronnie Sahlberg 2021-07-21  3645  	}
f5db424b3e14aa Ronnie Sahlberg 2021-07-21 @3646  	return rc;
966a3cb7c7db78 Ronnie Sahlberg 2021-06-03  3647  }
966a3cb7c7db78 Ronnie Sahlberg 2021-06-03  3648  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 39368 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread
[parent not found: <CGME20210721015429epcas1p4654c2b9348101aa7967bfe60d1d8da71@epcas1p4.samsung.com>]
* [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; 9+ 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] 9+ messages in thread

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

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-21  0:49 [PATCH] cifs: only write 64kb at a time when fallocating a small region of a file Ronnie Sahlberg
2021-07-21  0:50 Ronnie Sahlberg
2021-07-21  3:15 kernel test robot
     [not found] <CGME20210721015429epcas1p4654c2b9348101aa7967bfe60d1d8da71@epcas1p4.samsung.com>
     [not found] ` <014c01d77dd3$57add320$07097960$@samsung.com>
2021-07-21  7:21   ` 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

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.