[PATCH 07/10] cifs: Reduce copy&paste in smb2_compound_op()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Don't duplicate calls to inner _init() calls when only the fid differs.

Signed-off-by: Volker Lendecke <vl@xxxxxxxxx>
---
 fs/cifs/smb2inode.c | 102 ++++++++++++--------------------------------
 1 file changed, 28 insertions(+), 74 deletions(-)

diff --git a/fs/cifs/smb2inode.c b/fs/cifs/smb2inode.c
index 1aafa79503ce..cc472602daf0 100644
--- a/fs/cifs/smb2inode.c
+++ b/fs/cifs/smb2inode.c
@@ -38,6 +38,8 @@ free_set_inf_compound(struct smb_rqst *rqst)
 
 struct cop_vars {
 	struct cifs_open_parms oparms;
+	__u64 persistent_fid;
+	__u64 volatile_fid;
 	struct kvec rsp_iov[3];
 	struct smb_rqst rqst[3];
 	struct kvec open_iov[SMB2_CREATE_IOV_SIZE];
@@ -92,8 +94,13 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
 		flags |= CIFS_TRANSFORM_REQ;
 
 	/* We already have a handle so we can skip the open */
-	if (cfile)
+	if (cfile) {
+		vars->persistent_fid = cfile->fid.persistent_fid;
+		vars->volatile_fid = cfile->fid.volatile_fid;
 		goto after_open;
+	} else {
+		vars->persistent_fid = vars->volatile_fid = COMPOUND_FID;
+	}
 
 	/* Open */
 	utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
@@ -132,26 +139,14 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
 		rqst[num_rqst].rq_iov = &vars->qi_iov[0];
 		rqst[num_rqst].rq_nvec = 1;
 
-		if (cfile)
-			rc = SMB2_query_info_init(tcon, server,
-				&rqst[num_rqst],
-				cfile->fid.persistent_fid,
-				cfile->fid.volatile_fid,
-				FILE_ALL_INFORMATION,
-				SMB2_O_INFO_FILE, 0,
-				sizeof(struct smb2_file_all_info) +
-					  PATH_MAX * 2, 0, NULL);
-		else {
-			rc = SMB2_query_info_init(tcon, server,
+		rc = SMB2_query_info_init(tcon, server,
 				&rqst[num_rqst],
-				COMPOUND_FID,
-				COMPOUND_FID,
+				vars->persistent_fid,
+				vars->volatile_fid,
 				FILE_ALL_INFORMATION,
 				SMB2_O_INFO_FILE, 0,
 				sizeof(struct smb2_file_all_info) +
 					  PATH_MAX * 2, 0, NULL);
-		}
-
 		if (rc)
 			goto finished;
 		if (!cfile) {
@@ -166,27 +161,15 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
 		rqst[num_rqst].rq_iov = &vars->qi_iov[0];
 		rqst[num_rqst].rq_nvec = 1;
 
-		if (cfile)
-			rc = SMB2_query_info_init(tcon, server,
+		rc = SMB2_query_info_init(tcon, server,
 				&rqst[num_rqst],
-				cfile->fid.persistent_fid,
-				cfile->fid.volatile_fid,
+				vars->persistent_fid,
+				vars->volatile_fid,
 				SMB_FIND_FILE_POSIX_INFO,
 				SMB2_O_INFO_FILE, 0,
 				/* TBD: fix following to allow for longer SIDs */
 				sizeof(struct smb311_posix_qinfo *) + (PATH_MAX * 2) +
 				(sizeof(struct cifs_sid) * 2), 0, NULL);
-		else {
-			rc = SMB2_query_info_init(tcon, server,
-				&rqst[num_rqst],
-				COMPOUND_FID,
-				COMPOUND_FID,
-				SMB_FIND_FILE_POSIX_INFO,
-				SMB2_O_INFO_FILE, 0,
-				sizeof(struct smb311_posix_qinfo *) + (PATH_MAX * 2) +
-				(sizeof(struct cifs_sid) * 2), 0, NULL);
-		}
-
 		if (rc)
 			goto finished;
 		if (!cfile) {
@@ -216,25 +199,14 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
 		size[0] = 8; /* sizeof __le64 */
 		data[0] = ptr;
 
-		if (cfile) {
-			rc = SMB2_set_info_init(tcon, server,
-						&rqst[num_rqst],
-						cfile->fid.persistent_fid,
-						cfile->fid.volatile_fid,
-						current->tgid,
-						FILE_END_OF_FILE_INFORMATION,
-						SMB2_O_INFO_FILE, 0,
-						data, size);
-		} else {
-			rc = SMB2_set_info_init(tcon, server,
-						&rqst[num_rqst],
-						COMPOUND_FID,
-						COMPOUND_FID,
-						current->tgid,
-						FILE_END_OF_FILE_INFORMATION,
-						SMB2_O_INFO_FILE, 0,
-						data, size);
-		}
+		rc = SMB2_set_info_init(tcon, server,
+					&rqst[num_rqst],
+					vars->persistent_fid,
+					vars->volatile_fid,
+					current->tgid,
+					FILE_END_OF_FILE_INFORMATION,
+					SMB2_O_INFO_FILE, 0,
+					data, size);
 		if (rc)
 			goto finished;
 		if (!cfile) {
@@ -252,22 +224,12 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
 		size[0] = sizeof(FILE_BASIC_INFO);
 		data[0] = ptr;
 
-		if (cfile)
-			rc = SMB2_set_info_init(tcon, server,
-				&rqst[num_rqst],
-				cfile->fid.persistent_fid,
-				cfile->fid.volatile_fid, current->tgid,
-				FILE_BASIC_INFORMATION,
-				SMB2_O_INFO_FILE, 0, data, size);
-		else {
-			rc = SMB2_set_info_init(tcon, server,
+		rc = SMB2_set_info_init(tcon, server,
 				&rqst[num_rqst],
-				COMPOUND_FID,
-				COMPOUND_FID, current->tgid,
+				vars->persistent_fid,
+				vars->volatile_fid, current->tgid,
 				FILE_BASIC_INFORMATION,
 				SMB2_O_INFO_FILE, 0, data, size);
-		}
-
 		if (rc)
 			goto finished;
 		if (!cfile) {
@@ -294,20 +256,12 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,
 		size[1] = len + 2 /* null */;
 		data[1] = (__le16 *)ptr;
 
-		if (cfile)
-			rc = SMB2_set_info_init(tcon, server,
-						&rqst[num_rqst],
-						cfile->fid.persistent_fid,
-						cfile->fid.volatile_fid,
-					current->tgid, FILE_RENAME_INFORMATION,
-					SMB2_O_INFO_FILE, 0, data, size);
-		else {
-			rc = SMB2_set_info_init(tcon, server,
+		rc = SMB2_set_info_init(tcon, server,
 					&rqst[num_rqst],
-					COMPOUND_FID, COMPOUND_FID,
+					vars->persistent_fid,
+					vars->volatile_fid,
 					current->tgid, FILE_RENAME_INFORMATION,
 					SMB2_O_INFO_FILE, 0, data, size);
-		}
 		if (rc)
 			goto finished;
 		if (!cfile) {
-- 
2.30.2




[Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux