LVS

첨부:

Makefile - module programing Makefile 예시
ip_vs_rr.c - Round Robin 코드 (Linux kernel 원본에 존재)


sequence
1) ip_vs_rr.c를 적절히 수정.
2) Make 하여, Module 생성. (ip_vs_rr.ko)
3) 2)에서 생성한 파일을 /lib/module/(해당커널 버전)/kernel/net/netfilter/ipvs 로 복사
4) ipvs 실행 및 확인



팁 : 
1)  Line by Line
2) insmod : module 올림
    rmmod : mudule  내림
3) printk(""); 를 사용하여, 코드의 실행 부분 확인가능 - printk("") 는 dmesg 로 확인 가능
                   dmesg -c >> dmesg 출력 clear
    




/*

* Round-Robin Scheduling

*/

int i=1, n=1;

static struct ip_vs_dest *

ip_vs_rr_schedule(struct ip_vs_service *svc, const struct sk_buff *skb)

{

struct list_head *p, *q;

struct ip_vs_dest *dest;

IP_VS_DBG(6, "%s(): Scheduling...\n", __func__);

write_lock(&svc->sched_lock);

p = (struct list_head *)svc->sched_data;

if(i==n) // 이부분이 실행되면, 서버가 바뀜. 사용한 조건으로 인해, n번만큼 할당됨.

p = p->next;

q = p;

do {

/* skip list head */

if (q == &svc->destinations) {

q = q->next;

continue;

}

dest = list_entry(q, struct ip_vs_dest, n_list);

if (!(dest->flags & IP_VS_DEST_F_OVERLOAD) &&

atomic_read(&dest->weight) > 0)

/* HIT */

goto out;

q = q->next;

} while (q != p);

write_unlock(&svc->sched_lock);

IP_VS_ERR_RL("RR: no destination available\n");

return NULL;

out:

svc->sched_data = q;

write_unlock(&svc->sched_lock);

IP_VS_DBG_BUF(6, "RR: server %s:%u "

"activeconns %d refcnt %d weight %d\n",

IP_VS_DBG_ADDR(svc->af, &dest->addr), ntohs(dest->port),

atomic_read(&dest->activeconns),

atomic_read(&dest->refcnt), atomic_read(&dest->weight));

if(i==n){

n++;i=0;

}

i++;

return dest;

}

 


'LVS' 카테고리의 다른 글

IPVS Configuration : DR (Direct Routing)  (0) 2010.12.29
LVS 구축에 관한 이론 (NAT 부터 WLC 까지)  (2) 2010.12.23
커널 소켓 프로그래밍  (0) 2010.11.20
모듈 프로그래밍  (1) 2010.11.10
ipvsadm 소스 파일 make하기  (1) 2010.11.09
 

New Post