[6/9] cifs: change SMB2_OP_SET_EOF to use compounding
diff mbox series

Message ID 20180820033920.31435-7-lsahlber@redhat.com
State New
Headers show
Series
  • [1/9] cifs: add a smb2_compound_op and change QUERY_INFO to use it
Related show

Commit Message

Ronnie Sahlberg Aug. 20, 2018, 3:39 a.m. UTC
This changes SMB2_OP_SET_EOF to use compounding in some situations.
This is part of the path based API to truncate a file.
Most of the time this will however not be invoked for SMB2 since
cifs_set_file_size() will as far as I can tell almost always just
open the file synchronously and switch to the handle based truncate
code path, thus bypassing the compounding we add here.

Rewriting cifs_set_file_size() and make that whole pile of code more
compounding friendly, and also easier to read and understand, is a
different project though and not for this patch.

Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
---
 fs/cifs/smb2inode.c | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)

Patch
diff mbox series

diff --git a/fs/cifs/smb2inode.c b/fs/cifs/smb2inode.c
index a9b36c2329ae..8822b5937449 100644
--- a/fs/cifs/smb2inode.c
+++ b/fs/cifs/smb2inode.c
@@ -131,6 +131,21 @@  smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
 		smb2_set_next_command(server, &rqst[num_rqst]);
 		smb2_set_related(&rqst[num_rqst++]);
 		break;
+	case SMB2_OP_SET_EOF:
+		memset(&si_iov, 0, sizeof(si_iov));
+		rqst[num_rqst].rq_iov = si_iov;
+		rqst[num_rqst].rq_nvec = 1;
+
+		/* data already contain eof */
+		size = 8; /* sizeof __le64 */
+
+		rc = SMB2_set_info_init(tcon, &rqst[num_rqst], COMPOUND_FID,
+					COMPOUND_FID, current->tgid,
+					FILE_END_OF_FILE_INFORMATION,
+					SMB2_O_INFO_FILE, 0, &data, &size);
+		smb2_set_next_command(server, &rqst[num_rqst]);
+		smb2_set_related(&rqst[num_rqst++]);
+		break;
 	default:
 		cifs_dbg(VFS, "Invalid command\n");
 		rc = -EINVAL;
@@ -170,6 +185,7 @@  smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
 	case SMB2_OP_MKDIR:
 		SMB2_close_free(&rqst[1]);
 		break;
+	case SMB2_OP_SET_EOF:
 	case SMB2_OP_RMDIR:
 		SMB2_set_info_free(&rqst[1]);
 		SMB2_close_free(&rqst[2]);
@@ -232,11 +248,6 @@  smb2_open_op_close(const unsigned int xid, struct cifs_tcon *tcon,
 		tmprc = SMB2_set_hardlink(xid, tcon, fid.persistent_fid,
 					  fid.volatile_fid, (__le16 *)data);
 		break;
-	case SMB2_OP_SET_EOF:
-		tmprc = SMB2_set_eof(xid, tcon, fid.persistent_fid,
-				     fid.volatile_fid, current->tgid,
-				     (__le64 *)data, false);
-		break;
 	case SMB2_OP_SET_INFO:
 		tmprc = SMB2_set_basic_info(xid, tcon, fid.persistent_fid,
 					    fid.volatile_fid,
@@ -396,9 +407,10 @@  smb2_set_path_size(const unsigned int xid, struct cifs_tcon *tcon,
 		   struct cifs_sb_info *cifs_sb, bool set_alloc)
 {
 	__le64 eof = cpu_to_le64(size);
-	return smb2_open_op_close(xid, tcon, cifs_sb, full_path,
-				  FILE_WRITE_DATA, FILE_OPEN, 0, &eof,
-				  SMB2_OP_SET_EOF);
+
+	return smb2_compound_op(xid, tcon, cifs_sb, full_path,
+				FILE_WRITE_DATA, FILE_OPEN, 0, &eof,
+				SMB2_OP_SET_EOF);
 }
 
 int