1 #define KMSG_COMPONENT "IPVS"
2 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
4 #include <linux/module.h>
5 #include <linux/spinlock.h>
6 #include <linux/interrupt.h>
7 #include <asm/string.h>
8 #include <linux/kmod.h>
9 #include <linux/sysctl.h>
11 #include <net/ip_vs.h>
14 static LIST_HEAD(ip_vs_pe
);
16 /* lock for service table */
17 static DEFINE_SPINLOCK(ip_vs_pe_lock
);
19 /* Bind a service with a pe */
20 void ip_vs_bind_pe(struct ip_vs_service
*svc
, struct ip_vs_pe
*pe
)
25 /* Unbind a service from its pe */
26 void ip_vs_unbind_pe(struct ip_vs_service
*svc
)
31 /* Get pe in the pe list by name */
32 struct ip_vs_pe
*__ip_vs_pe_getbyname(const char *pe_name
)
36 IP_VS_DBG(10, "%s(): pe_name \"%s\"\n", __func__
,
39 spin_lock_bh(&ip_vs_pe_lock
);
41 list_for_each_entry(pe
, &ip_vs_pe
, n_list
) {
42 /* Test and get the modules atomically */
44 !try_module_get(pe
->module
)) {
45 /* This pe is just deleted */
48 if (strcmp(pe_name
, pe
->name
)==0) {
50 spin_unlock_bh(&ip_vs_pe_lock
);
54 module_put(pe
->module
);
57 spin_unlock_bh(&ip_vs_pe_lock
);
61 /* Lookup pe and try to load it if it doesn't exist */
62 struct ip_vs_pe
*ip_vs_pe_getbyname(const char *name
)
66 /* Search for the pe by name */
67 pe
= __ip_vs_pe_getbyname(name
);
69 /* If pe not found, load the module and search again */
71 request_module("ip_vs_pe_%s", name
);
72 pe
= __ip_vs_pe_getbyname(name
);
78 /* Register a pe in the pe list */
79 int register_ip_vs_pe(struct ip_vs_pe
*pe
)
83 /* increase the module use count */
84 ip_vs_use_count_inc();
86 spin_lock_bh(&ip_vs_pe_lock
);
88 if (!list_empty(&pe
->n_list
)) {
89 spin_unlock_bh(&ip_vs_pe_lock
);
90 ip_vs_use_count_dec();
91 pr_err("%s(): [%s] pe already linked\n",
96 /* Make sure that the pe with this name doesn't exist
99 list_for_each_entry(tmp
, &ip_vs_pe
, n_list
) {
100 if (strcmp(tmp
->name
, pe
->name
) == 0) {
101 spin_unlock_bh(&ip_vs_pe_lock
);
102 ip_vs_use_count_dec();
103 pr_err("%s(): [%s] pe already existed "
104 "in the system\n", __func__
, pe
->name
);
108 /* Add it into the d-linked pe list */
109 list_add(&pe
->n_list
, &ip_vs_pe
);
110 spin_unlock_bh(&ip_vs_pe_lock
);
112 pr_info("[%s] pe registered.\n", pe
->name
);
116 EXPORT_SYMBOL_GPL(register_ip_vs_pe
);
118 /* Unregister a pe from the pe list */
119 int unregister_ip_vs_pe(struct ip_vs_pe
*pe
)
121 spin_lock_bh(&ip_vs_pe_lock
);
122 if (list_empty(&pe
->n_list
)) {
123 spin_unlock_bh(&ip_vs_pe_lock
);
124 pr_err("%s(): [%s] pe is not in the list. failed\n",
129 /* Remove it from the d-linked pe list */
130 list_del(&pe
->n_list
);
131 spin_unlock_bh(&ip_vs_pe_lock
);
133 /* decrease the module use count */
134 ip_vs_use_count_dec();
136 pr_info("[%s] pe unregistered.\n", pe
->name
);
140 EXPORT_SYMBOL_GPL(unregister_ip_vs_pe
);