mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00

This patch adds a new struct member sched in struct mptcp_sock. And two helpers mptcp_init_sched() and mptcp_release_sched() to init and release it. Init it with the sysctl scheduler in mptcp_init_sock(), copy the scheduler from the parent in mptcp_sk_clone(), and release it in __mptcp_destroy_sock(). Acked-by: Paolo Abeni <pabeni@redhat.com> Reviewed-by: Mat Martineau <martineau@kernel.org> Signed-off-by: Geliang Tang <geliang.tang@suse.com> Signed-off-by: Mat Martineau <martineau@kernel.org> Link: https://lore.kernel.org/r/20230821-upstream-net-next-20230818-v1-5-0c860fb256a8@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
89 lines
1.7 KiB
C
89 lines
1.7 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/* Multipath TCP
|
|
*
|
|
* Copyright (c) 2022, SUSE.
|
|
*/
|
|
|
|
#define pr_fmt(fmt) "MPTCP: " fmt
|
|
|
|
#include <linux/kernel.h>
|
|
#include <linux/module.h>
|
|
#include <linux/list.h>
|
|
#include <linux/rculist.h>
|
|
#include <linux/spinlock.h>
|
|
#include "protocol.h"
|
|
|
|
static DEFINE_SPINLOCK(mptcp_sched_list_lock);
|
|
static LIST_HEAD(mptcp_sched_list);
|
|
|
|
/* Must be called with rcu read lock held */
|
|
struct mptcp_sched_ops *mptcp_sched_find(const char *name)
|
|
{
|
|
struct mptcp_sched_ops *sched, *ret = NULL;
|
|
|
|
list_for_each_entry_rcu(sched, &mptcp_sched_list, list) {
|
|
if (!strcmp(sched->name, name)) {
|
|
ret = sched;
|
|
break;
|
|
}
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
int mptcp_register_scheduler(struct mptcp_sched_ops *sched)
|
|
{
|
|
if (!sched->get_subflow)
|
|
return -EINVAL;
|
|
|
|
spin_lock(&mptcp_sched_list_lock);
|
|
if (mptcp_sched_find(sched->name)) {
|
|
spin_unlock(&mptcp_sched_list_lock);
|
|
return -EEXIST;
|
|
}
|
|
list_add_tail_rcu(&sched->list, &mptcp_sched_list);
|
|
spin_unlock(&mptcp_sched_list_lock);
|
|
|
|
pr_debug("%s registered", sched->name);
|
|
return 0;
|
|
}
|
|
|
|
void mptcp_unregister_scheduler(struct mptcp_sched_ops *sched)
|
|
{
|
|
spin_lock(&mptcp_sched_list_lock);
|
|
list_del_rcu(&sched->list);
|
|
spin_unlock(&mptcp_sched_list_lock);
|
|
}
|
|
|
|
int mptcp_init_sched(struct mptcp_sock *msk,
|
|
struct mptcp_sched_ops *sched)
|
|
{
|
|
if (!sched)
|
|
goto out;
|
|
|
|
if (!bpf_try_module_get(sched, sched->owner))
|
|
return -EBUSY;
|
|
|
|
msk->sched = sched;
|
|
if (msk->sched->init)
|
|
msk->sched->init(msk);
|
|
|
|
pr_debug("sched=%s", msk->sched->name);
|
|
|
|
out:
|
|
return 0;
|
|
}
|
|
|
|
void mptcp_release_sched(struct mptcp_sock *msk)
|
|
{
|
|
struct mptcp_sched_ops *sched = msk->sched;
|
|
|
|
if (!sched)
|
|
return;
|
|
|
|
msk->sched = NULL;
|
|
if (sched->release)
|
|
sched->release(msk);
|
|
|
|
bpf_module_put(sched, sched->owner);
|
|
}
|