ip_vs_ovf.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * IPVS: Overflow-Connection Scheduling module
  3. *
  4. * Authors: Raducu Deaconu <rhadoo_io@yahoo.com>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. *
  11. * Scheduler implements "overflow" loadbalancing according to number of active
  12. * connections , will keep all conections to the node with the highest weight
  13. * and overflow to the next node if the number of connections exceeds the node's
  14. * weight.
  15. * Note that this scheduler might not be suitable for UDP because it only uses
  16. * active connections
  17. *
  18. */
  19. #define KMSG_COMPONENT "IPVS"
  20. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  21. #include <linux/module.h>
  22. #include <linux/kernel.h>
  23. #include <net/ip_vs.h>
  24. /* OVF Connection scheduling */
  25. static struct ip_vs_dest *
  26. ip_vs_ovf_schedule(struct ip_vs_service *svc, const struct sk_buff *skb,
  27. struct ip_vs_iphdr *iph)
  28. {
  29. struct ip_vs_dest *dest, *h = NULL;
  30. int hw = 0, w;
  31. IP_VS_DBG(6, "ip_vs_ovf_schedule(): Scheduling...\n");
  32. /* select the node with highest weight, go to next in line if active
  33. * connections exceed weight
  34. */
  35. list_for_each_entry_rcu(dest, &svc->destinations, n_list) {
  36. w = atomic_read(&dest->weight);
  37. if ((dest->flags & IP_VS_DEST_F_OVERLOAD) ||
  38. atomic_read(&dest->activeconns) > w ||
  39. w == 0)
  40. continue;
  41. if (!h || w > hw) {
  42. h = dest;
  43. hw = w;
  44. }
  45. }
  46. if (h) {
  47. IP_VS_DBG_BUF(6, "OVF: server %s:%u active %d w %d\n",
  48. IP_VS_DBG_ADDR(h->af, &h->addr),
  49. ntohs(h->port),
  50. atomic_read(&h->activeconns),
  51. atomic_read(&h->weight));
  52. return h;
  53. }
  54. ip_vs_scheduler_err(svc, "no destination available");
  55. return NULL;
  56. }
  57. static struct ip_vs_scheduler ip_vs_ovf_scheduler = {
  58. .name = "ovf",
  59. .refcnt = ATOMIC_INIT(0),
  60. .module = THIS_MODULE,
  61. .n_list = LIST_HEAD_INIT(ip_vs_ovf_scheduler.n_list),
  62. .schedule = ip_vs_ovf_schedule,
  63. };
  64. static int __init ip_vs_ovf_init(void)
  65. {
  66. return register_ip_vs_scheduler(&ip_vs_ovf_scheduler);
  67. }
  68. static void __exit ip_vs_ovf_cleanup(void)
  69. {
  70. unregister_ip_vs_scheduler(&ip_vs_ovf_scheduler);
  71. synchronize_rcu();
  72. }
  73. module_init(ip_vs_ovf_init);
  74. module_exit(ip_vs_ovf_cleanup);
  75. MODULE_LICENSE("GPL");