Skip to content

Commit

Permalink
ipvs, refactoring: use links to vs->vsg links
Browse files Browse the repository at this point in the history
ipvs_cmd: removed vs_group list parameter. Link to vsg is obtained via vs->vsg.

These functions are also modified in the same way:
ipvs_group_cmd, clear_service_rs, clear_service_vs, clear_diff_rs.

clear_diff_vsg: new_vs is passed as a param, vsg pointers are retrieved w/o iterating
  • Loading branch information
andriyanov committed Feb 5, 2015
1 parent 09de441 commit 5503008
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 38 deletions.
16 changes: 8 additions & 8 deletions keepalived/check/ipvswrapper.c
Expand Up @@ -140,9 +140,9 @@ ipvs_group_range_cmd(int cmd, virtual_server_group_entry_t *vsg_entry)

/* set IPVS group rules */
static int
ipvs_group_cmd(int cmd, list vs_group, real_server_t * rs, char * vsgname)
ipvs_group_cmd(int cmd, virtual_server_t * vs, real_server_t * rs)
{
virtual_server_group_t *vsg = ipvs_get_group_by_name(vsgname, vs_group);
virtual_server_group_t *vsg = vs->vsg;
virtual_server_group_entry_t *vsg_entry;
list l;
element e;
Expand Down Expand Up @@ -234,7 +234,7 @@ ipvs_set_rule(int cmd, virtual_server_t * vs, real_server_t * rs)

/* Set/Remove a RS from a VS */
int
ipvs_cmd(int cmd, list vs_group, virtual_server_t * vs, real_server_t * rs)
ipvs_cmd(int cmd, virtual_server_t * vs, real_server_t * rs)
{
int err = 0;

Expand All @@ -257,7 +257,7 @@ ipvs_cmd(int cmd, list vs_group, virtual_server_t * vs, real_server_t * rs)

/* Set vs rule and send to kernel */
if (vs->vsgname) {
err = ipvs_group_cmd(cmd, vs_group, rs, vs->vsgname);
err = ipvs_group_cmd(cmd, vs, rs);
} else {
if (vs->vfwmark) {
urule->vfwmark = vs->vfwmark;
Expand Down Expand Up @@ -454,9 +454,9 @@ ipvs_group_range_cmd(int cmd, virtual_server_group_entry_t *vsg_entry)

/* set IPVS group rules */
static void
ipvs_group_cmd(int cmd, list vs_group, real_server_t * rs, virtual_server_t * vs)
ipvs_group_cmd(int cmd, virtual_server_t * vs, real_server_t * rs)
{
virtual_server_group_t *vsg = ipvs_get_group_by_name(vs->vsgname, vs_group);
virtual_server_group_t *vsg = vs->vsg;
virtual_server_group_entry_t *vsg_entry;
list l;
element e;
Expand Down Expand Up @@ -570,7 +570,7 @@ ipvs_set_rule(int cmd, virtual_server_t * vs, real_server_t * rs)

/* Set/Remove a RS from a VS */
int
ipvs_cmd(int cmd, list vs_group, virtual_server_t * vs, real_server_t * rs)
ipvs_cmd(int cmd, virtual_server_t * vs, real_server_t * rs)
{
/* Allocate the room */
memset(srule, 0, sizeof(ipvs_service_t));
Expand All @@ -592,7 +592,7 @@ ipvs_cmd(int cmd, list vs_group, virtual_server_t * vs, real_server_t * rs)

/* Set vs rule and send to kernel */
if (vs->vsgname) {
ipvs_group_cmd(cmd, vs_group, rs, vs);
ipvs_group_cmd(cmd, vs, rs);
} else {
if (vs->vfwmark) {
srule->af = AF_INET;
Expand Down
52 changes: 23 additions & 29 deletions keepalived/check/ipwrapper.c
Expand Up @@ -52,7 +52,7 @@ weigh_live_realservers(virtual_server_t * vs)

/* Remove a realserver IPVS rule */
static int
clear_service_rs(list vs_group, virtual_server_t * vs, list l)
clear_service_rs(virtual_server_t * vs, list l)
{
element e;
real_server_t *rs;
Expand All @@ -65,7 +65,7 @@ clear_service_rs(list vs_group, virtual_server_t * vs, list l)
log_message(LOG_INFO, "Removing service %s from VS %s"
, FMT_RS(rs)
, FMT_VS(vs));
if (!ipvs_cmd(LVS_CMD_DEL_DEST, vs_group, vs, rs))
if (!ipvs_cmd(LVS_CMD_DEL_DEST, vs, rs))
return 0;
UNSET_ALIVE(rs);
if (!vs->omega)
Expand Down Expand Up @@ -113,20 +113,20 @@ clear_service_rs(list vs_group, virtual_server_t * vs, list l)

/* Remove a virtualserver IPVS rule */
static int
clear_service_vs(list vs_group, virtual_server_t * vs)
clear_service_vs(virtual_server_t * vs)
{
/* Processing real server queue */
if (!LIST_ISEMPTY(vs->rs)) {
if (vs->s_svr) {
if (ISALIVE(vs->s_svr))
if (!ipvs_cmd(LVS_CMD_DEL_DEST, vs_group, vs, vs->s_svr))
if (!ipvs_cmd(LVS_CMD_DEL_DEST, vs, vs->s_svr))
return 0;
} else if (!clear_service_rs(vs_group, vs, vs->rs))
} else if (!clear_service_rs(vs, vs->rs))
return 0;
/* The above will handle Omega case for VS as well. */
}

if (!ipvs_cmd(LVS_CMD_DEL, vs_group, vs, NULL))
if (!ipvs_cmd(LVS_CMD_DEL, vs, NULL))
return 0;

UNSET_ALIVE(vs);
Expand All @@ -143,7 +143,7 @@ clear_services(void)

for (e = LIST_HEAD(l); e; ELEMENT_NEXT(e)) {
vs = ELEMENT_DATA(e);
if (!clear_service_vs(check_data->vs_group, vs))
if (!clear_service_vs(vs))
return 0;
}
return 1;
Expand All @@ -170,9 +170,8 @@ init_service_rs(virtual_server_t * vs)
* add real servers into the VS pool. They will get there
* later upon healthchecks recovery (if ever).
*/

if (!vs->alpha && !ISALIVE(rs)) {
if (!ipvs_cmd(LVS_CMD_ADD_DEST, check_data->vs_group, vs, rs))
if (!ipvs_cmd(LVS_CMD_ADD_DEST, vs, rs))
return 0;
SET_ALIVE(rs);
}
Expand All @@ -187,7 +186,7 @@ init_service_vs(virtual_server_t * vs)
{
/* Init the VS root */
if (!ISALIVE(vs) || vs->vsgname) {
if (!ipvs_cmd(LVS_CMD_ADD, check_data->vs_group, vs, NULL))
if (!ipvs_cmd(LVS_CMD_ADD, vs, NULL))
return 0;
else
SET_ALIVE(vs);
Expand Down Expand Up @@ -239,7 +238,7 @@ perform_quorum_state(virtual_server_t *vs, int add)
continue;
if (add)
rs->alive = 0;
ipvs_cmd(add?LVS_CMD_ADD_DEST:LVS_CMD_DEL_DEST, check_data->vs_group, vs, rs);
ipvs_cmd(add?LVS_CMD_ADD_DEST:LVS_CMD_DEL_DEST, vs, rs);
rs->alive = 1;
}
}
Expand Down Expand Up @@ -268,7 +267,7 @@ update_quorum_state(virtual_server_t * vs)
, FMT_RS(vs->s_svr)
, FMT_VS(vs));

ipvs_cmd(LVS_CMD_DEL_DEST, check_data->vs_group, vs, vs->s_svr);
ipvs_cmd(LVS_CMD_DEL_DEST, vs, vs->s_svr);
vs->s_svr->alive = 0;

/* Adding back alive real servers */
Expand Down Expand Up @@ -312,7 +311,7 @@ update_quorum_state(virtual_server_t * vs)
, FMT_VS(vs));

/* the sorry server is now up in the pool, we flag it alive */
ipvs_cmd(LVS_CMD_ADD_DEST, check_data->vs_group, vs, vs->s_svr);
ipvs_cmd(LVS_CMD_ADD_DEST, vs, vs->s_svr);
vs->s_svr->alive = 1;

/* Remove remaining alive real servers */
Expand Down Expand Up @@ -343,7 +342,7 @@ perform_svr_state(int alive, virtual_server_t * vs, real_server_t * rs)
, FMT_VS(vs));
/* Add only if we have quorum or no sorry server */
if (vs->quorum_state == UP || !vs->s_svr || !ISALIVE(vs->s_svr)) {
ipvs_cmd(LVS_CMD_ADD_DEST, check_data->vs_group, vs, rs);
ipvs_cmd(LVS_CMD_ADD_DEST, vs, rs);
}
rs->alive = alive;
if (rs->notify_up) {
Expand Down Expand Up @@ -371,7 +370,7 @@ perform_svr_state(int alive, virtual_server_t * vs, real_server_t * rs)
* Remove only if we have quorum or no sorry server
*/
if (vs->quorum_state == UP || !vs->s_svr || !ISALIVE(vs->s_svr)) {
ipvs_cmd(LVS_CMD_DEL_DEST, check_data->vs_group, vs, rs);
ipvs_cmd(LVS_CMD_DEL_DEST, vs, rs);
}
rs->alive = alive;
if (rs->notify_down) {
Expand Down Expand Up @@ -410,7 +409,7 @@ update_svr_wgt(int weight, virtual_server_t * vs, real_server_t * rs)
*/
if (rs->set && ISALIVE(rs) &&
(vs->quorum_state == UP || !vs->s_svr || !ISALIVE(vs->s_svr)))
ipvs_cmd(LVS_CMD_EDIT_DEST, check_data->vs_group, vs, rs);
ipvs_cmd(LVS_CMD_EDIT_DEST, vs, rs);
update_quorum_state(vs);
}
}
Expand Down Expand Up @@ -523,14 +522,10 @@ clear_diff_vsge(list old, list new, virtual_server_t * old_vs)

/* Clear the diff vsg of the old vs */
static int
clear_diff_vsg(virtual_server_t * old_vs)
clear_diff_vsg(virtual_server_t * old_vs, virtual_server_t * new_vs)
{
virtual_server_group_t *old;
virtual_server_group_t *new;

/* Fetch group */
old = ipvs_get_group_by_name(old_vs->vsgname, old_check_data->vs_group);
new = ipvs_get_group_by_name(old_vs->vsgname, check_data->vs_group);
virtual_server_group_t *old = old_vs->vsg;
virtual_server_group_t *new = new_vs->vsg;

/* Diff the group entries */
if (!clear_diff_vsge(old->addr_ip, new->addr_ip, old_vs))
Expand Down Expand Up @@ -584,7 +579,7 @@ rs_exist(real_server_t * old_rs, list l)

/* Clear the diff rs of the old vs */
static int
clear_diff_rs(list old_vs_group, virtual_server_t * old_vs, list new_rs_list)
clear_diff_rs(virtual_server_t * old_vs, list new_rs_list)
{
element e;
list l = old_vs->rs;
Expand Down Expand Up @@ -621,7 +616,7 @@ clear_diff_rs(list old_vs_group, virtual_server_t * old_vs, list new_rs_list)
}
}
}
int ret = clear_service_rs (old_vs_group, old_vs, rs_to_remove);
int ret = clear_service_rs (old_vs, rs_to_remove);
free_list (rs_to_remove);

return ret;
Expand Down Expand Up @@ -658,7 +653,7 @@ clear_diff_services(void)
, FMT_VS(vs));

/* Clear VS entry */
if (!clear_service_vs(old_check_data->vs_group, vs))
if (!clear_service_vs(vs))
return 0;
} else {
/* copy status fields from old VS */
Expand All @@ -667,18 +662,17 @@ clear_diff_services(void)
new_vs->reloaded = 1;

if (vs->vsgname)
clear_diff_vsg(vs);
clear_diff_vsg(vs, new_vs);

/* If vs exist, perform rs pool diff */
/* omega = 0 must not prevent the notifiers from being called,
because the VS still exists in new configuration */
vs->omega = 1;
if (!clear_diff_rs(old_check_data->vs_group, vs, new_vs->rs))
if (!clear_diff_rs(vs, new_vs->rs))
return 0;
if (vs->s_svr)
if (ISALIVE(vs->s_svr))
if (!ipvs_cmd(LVS_CMD_DEL_DEST
, check_data->vs_group
, vs
, vs->s_svr))
return 0;
Expand Down
2 changes: 1 addition & 1 deletion keepalived/include/ipvswrapper.h
Expand Up @@ -93,7 +93,7 @@ extern int ipvs_start(void);
extern void ipvs_stop(void);
extern virtual_server_group_t *ipvs_get_group_by_name(char *, list);
extern int ipvs_group_remove_entry(virtual_server_t *, virtual_server_group_entry_t *);
extern int ipvs_cmd(int, list, virtual_server_t *, real_server_t *);
extern int ipvs_cmd(int, virtual_server_t *, real_server_t *);
extern int ipvs_syncd_cmd(int, char *, int, int);
extern void ipvs_syncd_master(char *, int);
extern void ipvs_syncd_backup(char *, int);
Expand Down

0 comments on commit 5503008

Please sign in to comment.