Skip to content

Commit 23d9b9b

Browse files
sprasad-microsoftSteve French
authored and
Steve French
committed
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: Shyam Prasad N <[email protected]> Reviewed-by: Paulo Alcantara (SUSE) <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 8abcaea commit 23d9b9b

File tree

3 files changed

+55
-51
lines changed

3 files changed

+55
-51
lines changed

fs/cifs/smb2misc.c

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -612,51 +612,52 @@ smb2_tcon_find_pending_open_lease(struct cifs_tcon *tcon,
612612
}
613613

614614
static bool
615-
smb2_is_valid_lease_break(char *buffer)
615+
smb2_is_valid_lease_break(char *buffer, struct TCP_Server_Info *server)
616616
{
617617
struct smb2_lease_break *rsp = (struct smb2_lease_break *)buffer;
618-
struct TCP_Server_Info *server;
618+
struct TCP_Server_Info *pserver;
619619
struct cifs_ses *ses;
620620
struct cifs_tcon *tcon;
621621
struct cifs_pending_open *open;
622622

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

625+
/* If server is a channel, select the primary channel */
626+
pserver = CIFS_SERVER_IS_CHAN(server) ? server->primary_server : server;
627+
625628
/* look up tcon based on tid & uid */
626629
spin_lock(&cifs_tcp_ses_lock);
627-
list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
628-
list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
629-
list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
630-
spin_lock(&tcon->open_file_lock);
631-
cifs_stats_inc(
632-
&tcon->stats.cifs_stats.num_oplock_brks);
633-
if (smb2_tcon_has_lease(tcon, rsp)) {
634-
spin_unlock(&tcon->open_file_lock);
635-
spin_unlock(&cifs_tcp_ses_lock);
636-
return true;
637-
}
638-
open = smb2_tcon_find_pending_open_lease(tcon,
639-
rsp);
640-
if (open) {
641-
__u8 lease_key[SMB2_LEASE_KEY_SIZE];
642-
struct tcon_link *tlink;
643-
644-
tlink = cifs_get_tlink(open->tlink);
645-
memcpy(lease_key, open->lease_key,
646-
SMB2_LEASE_KEY_SIZE);
647-
spin_unlock(&tcon->open_file_lock);
648-
spin_unlock(&cifs_tcp_ses_lock);
649-
smb2_queue_pending_open_break(tlink,
650-
lease_key,
651-
rsp->NewLeaseState);
652-
return true;
653-
}
630+
list_for_each_entry(ses, &pserver->smb_ses_list, smb_ses_list) {
631+
list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
632+
spin_lock(&tcon->open_file_lock);
633+
cifs_stats_inc(
634+
&tcon->stats.cifs_stats.num_oplock_brks);
635+
if (smb2_tcon_has_lease(tcon, rsp)) {
654636
spin_unlock(&tcon->open_file_lock);
637+
spin_unlock(&cifs_tcp_ses_lock);
638+
return true;
639+
}
640+
open = smb2_tcon_find_pending_open_lease(tcon,
641+
rsp);
642+
if (open) {
643+
__u8 lease_key[SMB2_LEASE_KEY_SIZE];
644+
struct tcon_link *tlink;
645+
646+
tlink = cifs_get_tlink(open->tlink);
647+
memcpy(lease_key, open->lease_key,
648+
SMB2_LEASE_KEY_SIZE);
649+
spin_unlock(&tcon->open_file_lock);
650+
spin_unlock(&cifs_tcp_ses_lock);
651+
smb2_queue_pending_open_break(tlink,
652+
lease_key,
653+
rsp->NewLeaseState);
654+
return true;
655+
}
656+
spin_unlock(&tcon->open_file_lock);
655657

656-
if (cached_dir_lease_break(tcon, rsp->LeaseKey)) {
657-
spin_unlock(&cifs_tcp_ses_lock);
658-
return true;
659-
}
658+
if (cached_dir_lease_break(tcon, rsp->LeaseKey)) {
659+
spin_unlock(&cifs_tcp_ses_lock);
660+
return true;
660661
}
661662
}
662663
}
@@ -689,7 +690,7 @@ smb2_is_valid_oplock_break(char *buffer, struct TCP_Server_Info *server)
689690
if (rsp->StructureSize !=
690691
smb2_rsp_struct_sizes[SMB2_OPLOCK_BREAK_HE]) {
691692
if (le16_to_cpu(rsp->StructureSize) == 44)
692-
return smb2_is_valid_lease_break(buffer);
693+
return smb2_is_valid_lease_break(buffer, server);
693694
else
694695
return false;
695696
}

fs/cifs/smb2ops.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4268,21 +4268,23 @@ init_sg(int num_rqst, struct smb_rqst *rqst, u8 *sign)
42684268
static int
42694269
smb2_get_enc_key(struct TCP_Server_Info *server, __u64 ses_id, int enc, u8 *key)
42704270
{
4271+
struct TCP_Server_Info *pserver;
42714272
struct cifs_ses *ses;
42724273
u8 *ses_enc_key;
42734274

4275+
/* If server is a channel, select the primary channel */
4276+
pserver = CIFS_SERVER_IS_CHAN(server) ? server->primary_server : server;
4277+
42744278
spin_lock(&cifs_tcp_ses_lock);
4275-
list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
4276-
list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
4277-
if (ses->Suid == ses_id) {
4278-
spin_lock(&ses->ses_lock);
4279-
ses_enc_key = enc ? ses->smb3encryptionkey :
4280-
ses->smb3decryptionkey;
4281-
memcpy(key, ses_enc_key, SMB3_ENC_DEC_KEY_SIZE);
4282-
spin_unlock(&ses->ses_lock);
4283-
spin_unlock(&cifs_tcp_ses_lock);
4284-
return 0;
4285-
}
4279+
list_for_each_entry(ses, &pserver->smb_ses_list, smb_ses_list) {
4280+
if (ses->Suid == ses_id) {
4281+
spin_lock(&ses->ses_lock);
4282+
ses_enc_key = enc ? ses->smb3encryptionkey :
4283+
ses->smb3decryptionkey;
4284+
memcpy(key, ses_enc_key, SMB3_ENC_DEC_KEY_SIZE);
4285+
spin_unlock(&ses->ses_lock);
4286+
spin_unlock(&cifs_tcp_ses_lock);
4287+
return 0;
42864288
}
42874289
}
42884290
spin_unlock(&cifs_tcp_ses_lock);

fs/cifs/smb2transport.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,19 @@ static
7777
int smb2_get_sign_key(__u64 ses_id, struct TCP_Server_Info *server, u8 *key)
7878
{
7979
struct cifs_chan *chan;
80+
struct TCP_Server_Info *pserver;
8081
struct cifs_ses *ses = NULL;
81-
struct TCP_Server_Info *it = NULL;
8282
int i;
8383
int rc = 0;
8484

8585
spin_lock(&cifs_tcp_ses_lock);
8686

87-
list_for_each_entry(it, &cifs_tcp_ses_list, tcp_ses_list) {
88-
list_for_each_entry(ses, &it->smb_ses_list, smb_ses_list) {
89-
if (ses->Suid == ses_id)
90-
goto found;
91-
}
87+
/* If server is a channel, select the primary channel */
88+
pserver = CIFS_SERVER_IS_CHAN(server) ? server->primary_server : server;
89+
90+
list_for_each_entry(ses, &pserver->smb_ses_list, smb_ses_list) {
91+
if (ses->Suid == ses_id)
92+
goto found;
9293
}
9394
cifs_server_dbg(VFS, "%s: Could not find session 0x%llx\n",
9495
__func__, ses_id);

0 commit comments

Comments
 (0)