Skip to content

Commit 35adffe

Browse files
aaptelsmfrench
authored andcommitted
cifs: sort interface list by speed
New channels are going to be opened by walking the list sequentially, so by sorting it we will connect to the fastest interfaces first. Signed-off-by: Aurelien Aptel <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent fa9c236 commit 35adffe

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

fs/cifs/smb2ops.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/falloc.h>
1111
#include <linux/scatterlist.h>
1212
#include <linux/uuid.h>
13+
#include <linux/sort.h>
1314
#include <crypto/aead.h>
1415
#include "cifsglob.h"
1516
#include "smb2pdu.h"
@@ -552,6 +553,13 @@ parse_server_interfaces(struct network_interface_info_ioctl_rsp *buf,
552553
return rc;
553554
}
554555

556+
static int compare_iface(const void *ia, const void *ib)
557+
{
558+
const struct cifs_server_iface *a = (struct cifs_server_iface *)ia;
559+
const struct cifs_server_iface *b = (struct cifs_server_iface *)ib;
560+
561+
return a->speed == b->speed ? 0 : (a->speed > b->speed ? -1 : 1);
562+
}
555563

556564
static int
557565
SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon)
@@ -581,6 +589,9 @@ SMB3_request_interfaces(const unsigned int xid, struct cifs_tcon *tcon)
581589
if (rc)
582590
goto out;
583591

592+
/* sort interfaces from fastest to slowest */
593+
sort(iface_list, iface_count, sizeof(*iface_list), compare_iface, NULL);
594+
584595
spin_lock(&ses->iface_lock);
585596
kfree(ses->iface_list);
586597
ses->iface_list = iface_list;

0 commit comments

Comments
 (0)