]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
ipvs: preparations for using rcu in schedulers
authorJulian Anastasov <ja@ssi.bg>
Fri, 22 Mar 2013 09:46:37 +0000 (11:46 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Mon, 1 Apr 2013 22:23:47 +0000 (00:23 +0200)
Allow schedulers to use rcu_dereference when
returning destination on lookup. The RCU read-side critical
section will allow ip_vs_bind_dest to get dest refcnt as
preparation for the step where destinations will be
deleted without an IP_VS_WAIT_WHILE guard that holds the
packet processing during update.

Add new optional scheduler methods add_dest,
del_dest and upd_dest. For now the methods are called
together with update_service but update_service will be
removed in a following change.

Signed-off-by: Julian Anastasov <ja@ssi.bg>
Signed-off-by: Simon Horman <horms@verge.net.au>
include/net/ip_vs.h
net/netfilter/ipvs/ip_vs_core.c
net/netfilter/ipvs/ip_vs_ctl.c

index 43886bb282fb0fe330d9fe0d69109b780d9d8c44..d91385c1b3a27960d20994f7a5c7e2853cdf66e9 100644 (file)
@@ -805,6 +805,12 @@ struct ip_vs_scheduler {
        int (*done_service)(struct ip_vs_service *svc);
        /* scheduler updating service */
        int (*update_service)(struct ip_vs_service *svc);
+       /* dest is linked */
+       int (*add_dest)(struct ip_vs_service *svc, struct ip_vs_dest *dest);
+       /* dest is unlinked */
+       int (*del_dest)(struct ip_vs_service *svc, struct ip_vs_dest *dest);
+       /* dest is updated */
+       int (*upd_dest)(struct ip_vs_service *svc, struct ip_vs_dest *dest);
 
        /* selecting a server from the given service */
        struct ip_vs_dest* (*schedule)(struct ip_vs_service *svc,
index 4fc749c6ec27073707a1874786d6cfed20bd3e60..939ad11ed534358466a99a4dfc67f3ff06f14dbf 100644 (file)
@@ -301,8 +301,10 @@ ip_vs_sched_persist(struct ip_vs_service *svc,
                 * template is not available.
                 * return *ignored=0 i.e. ICMP and NF_DROP
                 */
+               rcu_read_lock();
                dest = svc->scheduler->schedule(svc, skb);
                if (!dest) {
+                       rcu_read_unlock();
                        IP_VS_DBG(1, "p-schedule: no dest found.\n");
                        kfree(param.pe_data);
                        *ignored = 0;
@@ -318,6 +320,7 @@ ip_vs_sched_persist(struct ip_vs_service *svc,
                 * when the template expires */
                ct = ip_vs_conn_new(&param, &dest->addr, dport,
                                    IP_VS_CONN_F_TEMPLATE, dest, skb->mark);
+               rcu_read_unlock();
                if (ct == NULL) {
                        kfree(param.pe_data);
                        *ignored = -1;
@@ -446,8 +449,10 @@ ip_vs_schedule(struct ip_vs_service *svc, struct sk_buff *skb,
                return NULL;
        }
 
+       rcu_read_lock();
        dest = svc->scheduler->schedule(svc, skb);
        if (dest == NULL) {
+               rcu_read_unlock();
                IP_VS_DBG(1, "Schedule: no dest found.\n");
                return NULL;
        }
@@ -468,6 +473,7 @@ ip_vs_schedule(struct ip_vs_service *svc, struct sk_buff *skb,
                cp = ip_vs_conn_new(&p, &dest->addr,
                                    dest->port ? dest->port : pptr[1],
                                    flags, dest, skb->mark);
+               rcu_read_unlock();
                if (!cp) {
                        *ignored = -1;
                        return NULL;
index 182d95807bd59d0056ae5d39f6024f4b1000d148..d64f800a34269b250e6d62118785a20928b9cba4 100644 (file)
@@ -825,6 +825,11 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
        if (add) {
                list_add(&dest->n_list, &svc->destinations);
                svc->num_dests++;
+               if (svc->scheduler->add_dest)
+                       svc->scheduler->add_dest(svc, dest);
+       } else {
+               if (svc->scheduler->upd_dest)
+                       svc->scheduler->upd_dest(svc, dest);
        }
 
        /* call the update_service, because server weight may be changed */
@@ -1071,6 +1076,9 @@ static void __ip_vs_unlink_dest(struct ip_vs_service *svc,
        list_del(&dest->n_list);
        svc->num_dests--;
 
+       if (svcupd && svc->scheduler->del_dest)
+               svc->scheduler->del_dest(svc, dest);
+
        /*
         *  Call the update_service function of its scheduler
         */