~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/net/ipv4/ipvs/ip_vs_rr.c

Version: ~ [ linux-5.10-rc1 ] ~ [ linux-5.9.1 ] ~ [ linux-5.8.16 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.72 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.152 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.202 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.240 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.240 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * IPVS:        Round-Robin Scheduling module
  3  *
  4  * Version:     $Id: ip_vs_rr.c,v 1.9 2002/09/15 08:14:08 wensong Exp $
  5  *
  6  * Authors:     Wensong Zhang <wensong@linuxvirtualserver.org>
  7  *              Peter Kese <peter.kese@ijs.si>
  8  *
  9  *              This program is free software; you can redistribute it and/or
 10  *              modify it under the terms of the GNU General Public License
 11  *              as published by the Free Software Foundation; either version
 12  *              2 of the License, or (at your option) any later version.
 13  *
 14  * Fixes/Changes:
 15  *     Wensong Zhang            :     changed the ip_vs_rr_schedule to return dest
 16  *     Julian Anastasov         :     fixed the NULL pointer access bug in debugging
 17  *     Wensong Zhang            :     changed some comestics things for debugging
 18  *     Wensong Zhang            :     changed for the d-linked destination list
 19  *     Wensong Zhang            :     added the ip_vs_rr_update_svc
 20  *     Wensong Zhang            :     added any dest with weight=0 is quiesced
 21  *
 22  */
 23 
 24 #include <linux/config.h>
 25 #include <linux/module.h>
 26 #include <linux/init.h>
 27 #include <linux/types.h>
 28 #include <linux/kernel.h>
 29 #include <linux/errno.h>
 30 
 31 #include <net/ip_vs.h>
 32 
 33 
 34 static int ip_vs_rr_init_svc(struct ip_vs_service *svc)
 35 {
 36         svc->sched_data = &svc->destinations;
 37         return 0;
 38 }
 39 
 40 
 41 static int ip_vs_rr_done_svc(struct ip_vs_service *svc)
 42 {
 43         return 0;
 44 }
 45 
 46 
 47 static int ip_vs_rr_update_svc(struct ip_vs_service *svc)
 48 {
 49         svc->sched_data = &svc->destinations;
 50         return 0;
 51 }
 52 
 53 
 54 /*
 55  * Round-Robin Scheduling
 56  */
 57 static struct ip_vs_dest *
 58 ip_vs_rr_schedule(struct ip_vs_service *svc, const struct sk_buff *skb)
 59 {
 60         struct list_head *p, *q;
 61         struct ip_vs_dest *dest;
 62 
 63         IP_VS_DBG(6, "ip_vs_rr_schedule(): Scheduling...\n");
 64 
 65         write_lock(&svc->sched_lock);
 66         p = (struct list_head *)svc->sched_data;
 67         p = p->next;
 68         q = p;
 69         do {
 70                 /* skip list head */
 71                 if (q == &svc->destinations) {
 72                         q = q->next;
 73                         continue;
 74                 }
 75                 
 76                 dest = list_entry(q, struct ip_vs_dest, n_list);
 77                 if (!(dest->flags & IP_VS_DEST_F_OVERLOAD) &&
 78                     atomic_read(&dest->weight) > 0)
 79                         /* HIT */
 80                         goto out;
 81                 q = q->next;
 82         } while (q != p);
 83         write_unlock(&svc->sched_lock);
 84         return NULL;
 85 
 86   out:
 87         svc->sched_data = q;
 88         write_unlock(&svc->sched_lock);
 89         IP_VS_DBG(6, "RR: server %u.%u.%u.%u:%u "
 90                   "activeconns %d refcnt %d weight %d\n",
 91                   NIPQUAD(dest->addr), ntohs(dest->port),
 92                   atomic_read(&dest->activeconns),
 93                   atomic_read(&dest->refcnt), atomic_read(&dest->weight));
 94 
 95         return dest;
 96 }
 97 
 98 
 99 static struct ip_vs_scheduler ip_vs_rr_scheduler = {
100         .name =                 "rr",                   /* name */
101         .refcnt =               ATOMIC_INIT(0),
102         .module =               THIS_MODULE,
103         .init_service =         ip_vs_rr_init_svc,
104         .done_service =         ip_vs_rr_done_svc,
105         .update_service =       ip_vs_rr_update_svc,
106         .schedule =             ip_vs_rr_schedule,
107 };
108 
109 static int __init ip_vs_rr_init(void)
110 {
111         INIT_LIST_HEAD(&ip_vs_rr_scheduler.n_list);
112         return register_ip_vs_scheduler(&ip_vs_rr_scheduler);
113 }
114 
115 static void __exit ip_vs_rr_cleanup(void)
116 {
117         unregister_ip_vs_scheduler(&ip_vs_rr_scheduler);
118 }
119 
120 module_init(ip_vs_rr_init);
121 module_exit(ip_vs_rr_cleanup);
122 MODULE_LICENSE("GPL");
123 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp