Commit 23d9b9b7 authored by Shyam Prasad N's avatar Shyam Prasad N Committed by Steve French
Browse files

cifs: avoid unnecessary iteration of tcp sessions



In a few places, we do unnecessary iterations of
tcp sessions, even when the server struct is provided.

The change avoids it and uses the server struct provided.

Signed-off-by: default avatarShyam Prasad N <sprasad@microsoft.com>
Reviewed-by: default avatarPaulo Alcantara (SUSE) <pc@cjr.nz>
Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
parent 8abcaeae
Loading
Loading
Loading
Loading
+35 −34
Original line number Original line Diff line number Diff line
@@ -612,20 +612,22 @@ smb2_tcon_find_pending_open_lease(struct cifs_tcon *tcon,
}
}


static bool
static bool
smb2_is_valid_lease_break(char *buffer)
smb2_is_valid_lease_break(char *buffer, struct TCP_Server_Info *server)
{
{
	struct smb2_lease_break *rsp = (struct smb2_lease_break *)buffer;
	struct smb2_lease_break *rsp = (struct smb2_lease_break *)buffer;
	struct TCP_Server_Info *server;
	struct TCP_Server_Info *pserver;
	struct cifs_ses *ses;
	struct cifs_ses *ses;
	struct cifs_tcon *tcon;
	struct cifs_tcon *tcon;
	struct cifs_pending_open *open;
	struct cifs_pending_open *open;


	cifs_dbg(FYI, "Checking for lease break\n");
	cifs_dbg(FYI, "Checking for lease break\n");


	/* If server is a channel, select the primary channel */
	pserver = CIFS_SERVER_IS_CHAN(server) ? server->primary_server : server;

	/* look up tcon based on tid & uid */
	/* look up tcon based on tid & uid */
	spin_lock(&cifs_tcp_ses_lock);
	spin_lock(&cifs_tcp_ses_lock);
	list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
	list_for_each_entry(ses, &pserver->smb_ses_list, smb_ses_list) {
		list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
		list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
		list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
			spin_lock(&tcon->open_file_lock);
			spin_lock(&tcon->open_file_lock);
			cifs_stats_inc(
			cifs_stats_inc(
@@ -659,7 +661,6 @@ smb2_is_valid_lease_break(char *buffer)
			}
			}
		}
		}
	}
	}
	}
	spin_unlock(&cifs_tcp_ses_lock);
	spin_unlock(&cifs_tcp_ses_lock);
	cifs_dbg(FYI, "Can not process lease break - no lease matched\n");
	cifs_dbg(FYI, "Can not process lease break - no lease matched\n");
	trace_smb3_lease_not_found(le32_to_cpu(rsp->CurrentLeaseState),
	trace_smb3_lease_not_found(le32_to_cpu(rsp->CurrentLeaseState),
@@ -689,7 +690,7 @@ smb2_is_valid_oplock_break(char *buffer, struct TCP_Server_Info *server)
	if (rsp->StructureSize !=
	if (rsp->StructureSize !=
				smb2_rsp_struct_sizes[SMB2_OPLOCK_BREAK_HE]) {
				smb2_rsp_struct_sizes[SMB2_OPLOCK_BREAK_HE]) {
		if (le16_to_cpu(rsp->StructureSize) == 44)
		if (le16_to_cpu(rsp->StructureSize) == 44)
			return smb2_is_valid_lease_break(buffer);
			return smb2_is_valid_lease_break(buffer, server);
		else
		else
			return false;
			return false;
	}
	}
+13 −11
Original line number Original line Diff line number Diff line
@@ -4268,12 +4268,15 @@ init_sg(int num_rqst, struct smb_rqst *rqst, u8 *sign)
static int
static int
smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key)
smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key)
{
{
	struct TCP_Server_Info *pserver;
	struct cifs_ses *ses;
	struct cifs_ses *ses;
	u8 *ses_enc_key;
	u8 *ses_enc_key;


	/* If server is a channel, select the primary channel */
	pserver = CIFS_SERVER_IS_CHAN(server) ? server->primary_server : server;

	spin_lock(&cifs_tcp_ses_lock);
	spin_lock(&cifs_tcp_ses_lock);
	list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
	list_for_each_entry(ses, &pserver->smb_ses_list, smb_ses_list) {
		list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
		if (ses->Suid == ses_id) {
		if (ses->Suid == ses_id) {
			spin_lock(&ses->ses_lock);
			spin_lock(&ses->ses_lock);
			ses_enc_key = enc ? ses->smb3encryptionkey :
			ses_enc_key = enc ? ses->smb3encryptionkey :
@@ -4284,7 +4287,6 @@ smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key)
			return 0;
			return 0;
		}
		}
	}
	}
	}
	spin_unlock(&cifs_tcp_ses_lock);
	spin_unlock(&cifs_tcp_ses_lock);


	return -EAGAIN;
	return -EAGAIN;
+7 −6
Original line number Original line Diff line number Diff line
@@ -77,19 +77,20 @@ static
int smb2_get_sign_key(__u64 ses_id, struct TCP_Server_Info *server, u8 *key)
int smb2_get_sign_key(__u64 ses_id, struct TCP_Server_Info *server, u8 *key)
{
{
	struct cifs_chan *chan;
	struct cifs_chan *chan;
	struct TCP_Server_Info *pserver;
	struct cifs_ses *ses = NULL;
	struct cifs_ses *ses = NULL;
	struct TCP_Server_Info *it = NULL;
	int i;
	int i;
	int rc = 0;
	int rc = 0;


	spin_lock(&cifs_tcp_ses_lock);
	spin_lock(&cifs_tcp_ses_lock);


	list_for_each_entry(it, &cifs_tcp_ses_list, tcp_ses_list) {
	/* If server is a channel, select the primary channel */
		list_for_each_entry(ses, &it->smb_ses_list, smb_ses_list) {
	pserver = CIFS_SERVER_IS_CHAN(server) ? server->primary_server : server;

	list_for_each_entry(ses, &pserver->smb_ses_list, smb_ses_list) {
		if (ses->Suid == ses_id)
		if (ses->Suid == ses_id)
			goto found;
			goto found;
	}
	}
	}
	cifs_server_dbg(VFS, "%s: Could not find session 0x%llx\n",
	cifs_server_dbg(VFS, "%s: Could not find session 0x%llx\n",
			__func__, ses_id);
			__func__, ses_id);
	rc = -ENOENT;
	rc = -ENOENT;