Skip to content

Commit 663c284

Browse files
hac-vsmfrench
authored andcommitted
smb: client: fix cifs_pick_channel when channels are equally loaded
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>
1 parent 6de23f8 commit 663c284

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

fs/smb/client/transport.c

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

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

@@ -846,14 +851,8 @@ struct TCP_Server_Info *cifs_pick_channel(struct cifs_ses *ses)
846851
min_in_flight = server->in_flight;
847852
index = cur;
848853
}
849-
if (server->in_flight > max_in_flight)
850-
max_in_flight = server->in_flight;
851854
}
852855

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

0 commit comments

Comments
 (0)