Skip to contentSkip to conversation

cifs: fix incorrect handling of smb2_set_sparse() return in smb3_simple_falloc

PATCH In review Ronnie Sahlberg 2 participants 2 messages Mar 14, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cifs: fix incorrect handling of smb2_set_sparse() return in smb3_simple_falloc

smb2_set_sparse does not return -errno, it returns a boolean where true means success.
Change this to just ignore the return value just like the other callsites.

Additionally add code to handle the case where we must set the file sparse and possibly also extending it.

Fixes xfstests: generic/236 generic/350 generic/420

---
 fs/cifs/smb2ops.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
fs/cifs/smb2ops.c +12 -2
index 32dde87feaa9..03814b9f113d 100644
@@ -2718,6 +2718,7 @@ static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
 	struct cifsFileInfo *cfile = file->private_data;
 	long rc = -EOPNOTSUPP;
 	unsigned int xid;
+	__le64 eof;
 
 	xid = get_xid();
 
@@ -2777,9 +2778,18 @@ static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
 			return rc;
 		}
 
-		rc = smb2_set_sparse(xid, tcon, cfile, inode, false);
+		smb2_set_sparse(xid, tcon, cfile, inode, false);
+		rc = 0;
+	} else {
+		smb2_set_sparse(xid, tcon, cfile, inode, false);
+		rc = 0;
+		if (i_size_read(inode) < off + len) {
+			eof = cpu_to_le64(off + len);
+			rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
+					  cfile->fid.volatile_fid, cfile->pid,
+					  &eof);
+		}
 	}
-	/* BB: else ... in future add code to extend file and set sparse */
 
 	if (rc)
 		trace_smb3_falloc_err(xid, cfile->fid.persistent_fid, tcon->tid,
Signature · 1 line
2.13.6
#1 lore raw

Merged into cifs-2.6.git fo-next and kicked off the buildbot with current for-next

http://smb3-test-rhel-75.southcentralus.cloudapp.azure.com/#/builders/2/builds/162

Quoted 52 lines · Ronnie Sahlberg

smb2_set_sparse does not return -errno, it returns a boolean where true means success.
Change this to just ignore the return value just like the other callsites.

Additionally add code to handle the case where we must set the file sparse and possibly also extending it.

Fixes xfstests: generic/236 generic/350 generic/420

---
 fs/cifs/smb2ops.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
fs/cifs/smb2ops.c +12 -3
index 32dde87feaa9..03814b9f113d 100644
@@ -2718,6 +2718,7 @@ static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
        struct cifsFileInfo *cfile = file->private_data;
        long rc = -EOPNOTSUPP;
        unsigned int xid;
+       __le64 eof;
 
        xid = get_xid();
 
@@ -2777,9 +2778,18 @@ static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
                        return rc;
                }
 
-               rc = smb2_set_sparse(xid, tcon, cfile, inode, false);
+               smb2_set_sparse(xid, tcon, cfile, inode, false);
+               rc = 0;
+       } else {
+               smb2_set_sparse(xid, tcon, cfile, inode, false);
+               rc = 0;
+               if (i_size_read(inode) < off + len) {
+                       eof = cpu_to_le64(off + len);
+                       rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
+                                         cfile->fid.volatile_fid, cfile->pid,
+                                         &eof);
+               }
        }
-       /* BB: else ... in future add code to extend file and set sparse */
 
        if (rc)
                trace_smb3_falloc_err(xid, cfile->fid.persistent_fid, tcon->tid,
--

2.13.6

Signature · 3 lines
Thanks,

Steve