Skip to content

Commit 112bed0

Browse files
hac-vSasha Levin
authored andcommitted
smb: client: fix cifs_pick_channel when channels are equally loaded
commit 663c284 upstream. cifs_pick_channel uses (start % chan_count) when channels are equally loaded, but that can return a channel that failed the eligibility checks. Drop the fallback and return the scan-selected channel instead. If none is eligible, keep the existing behavior of using the primary channel. Signed-off-by: Henrique Carvalho <henrique.carvalho@suse.com> Acked-by: Paulo Alcantara (Red Hat) <pc@manguebit.org> Acked-by: Meetakshi Setiya <msetiya@microsoft.com> Reviewed-by: Shyam Prasad N <sprasad@microsoft.com> Cc: stable@vger.kernel.org Signed-off-by: Steve French <stfrench@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent ec174e3 commit 112bed0

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

fs/smb/client/transport.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -808,16 +808,21 @@ cifs_cancelled_callback(struct TCP_Server_Info *server, struct mid_q_entry *mid)
808808
}
809809

810810
/*
811-
* Return a channel (master if none) of @ses that can be used to send
812-
* regular requests.
811+
* cifs_pick_channel - pick an eligible channel for network operations
813812
*
814-
* If we are currently binding a new channel (negprot/sess.setup),
815-
* return the new incomplete channel.
813+
* @ses: session reference
814+
*
815+
* Select an eligible channel (not terminating and not marked as needing
816+
* reconnect), preferring the least loaded one. If no eligible channel is
817+
* found, fall back to the primary channel (index 0).
818+
*
819+
* Return: TCP_Server_Info pointer for the chosen channel, or NULL if @ses is
820+
* NULL.
816821
*/
817822
struct TCP_Server_Info *cifs_pick_channel(struct cifs_ses *ses)
818823
{
819824
uint index = 0;
820-
unsigned int min_in_flight = UINT_MAX, max_in_flight = 0;
825+
unsigned int min_in_flight = UINT_MAX;
821826
struct TCP_Server_Info *server = NULL;
822827
int i, start, cur;
823828

@@ -847,14 +852,8 @@ struct TCP_Server_Info *cifs_pick_channel(struct cifs_ses *ses)
847852
min_in_flight = server->in_flight;
848853
index = cur;
849854
}
850-
if (server->in_flight > max_in_flight)
851-
max_in_flight = server->in_flight;
852855
}
853856

854-
/* if all channels are equally loaded, fall back to round-robin */
855-
if (min_in_flight == max_in_flight)
856-
index = (uint)start % ses->chan_count;
857-
858857
server = ses->chans[index].server;
859858
spin_unlock(&ses->chan_lock);
860859

0 commit comments

Comments
 (0)