Skip to content

Commit

Permalink
Merge pull request #2380 from pqarmitage/updates
Browse files Browse the repository at this point in the history
Various IPVS updates for adding/removing real/sorry servers and changing inhibit
  • Loading branch information
pqarmitage authored Feb 5, 2024
2 parents b80fdaa + ba5f848 commit 967fcf0
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 27 deletions.
3 changes: 3 additions & 0 deletions doc/man/man5/keepalived.conf.5.in
Original file line number Diff line number Diff line change
Expand Up @@ -2336,6 +2336,9 @@ The syntax for virtual_server is :
# replaced with the sorry server.
\fBsorry_server \fR<IPADDR> [<PORT>]
# applies inhibit_on_failure behaviour to the sorry_server
# It is very unlikely that you want to use this, since if you
# have a real server available, you almost certainly want to use
# it.
\fBsorry_server_inhibit\fR
# Sorry server LVS forwarding method. Default is the virtual
# server's default.
Expand Down
4 changes: 3 additions & 1 deletion keepalived/check/check_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -755,8 +755,10 @@ dump_vs(FILE *fp, const virtual_server_t *vs)
, FMT_RS(vs->s_svr, vs));
dump_forwarding_method(fp, " ", vs->s_svr);
conf_write(fp, " Inhibit on failure is %s", vs->s_svr->inhibit ? "ON" : "OFF");
conf_write(fp, " set = %d", vs->s_svr->set);
conf_write(fp, " alive = %d", vs->s_svr->alive);
}
conf_write(fp, " alive = %d", vs->alive);
conf_write(fp, " VS alive = %d", vs->alive);
conf_write(fp, " quorum_state_up = %d", vs->quorum_state_up);
conf_write(fp, " reloaded = %d", vs->reloaded);

Expand Down
9 changes: 5 additions & 4 deletions keepalived/check/ipvswrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ ipvs_group_sync_entry(virtual_server_t *vs, virtual_server_group_entry_t *vsge)
if (rs->reloaded && (rs->alive || (rs->inhibit && rs->set))) {
/* Prepare the IPVS drule */
ipvs_set_drule(IP_VS_SO_SET_ADDDEST, &drule, rs);
drule.user.weight = rs->inhibit && !rs->alive ? 0 : real_weight(rs->effective_weight);
drule.user.weight = ((rs->inhibit && !rs->alive) || vs->s_svr->alive) ? 0 : real_weight(rs->effective_weight);

if (rs->forwarding_method != IP_VS_CONN_F_MASQ)
drule.user.port = inet_sockaddrport(&vsge->addr);
Expand All @@ -684,8 +684,9 @@ ipvs_group_sync_entry(virtual_server_t *vs, virtual_server_group_entry_t *vsge)
}
}

if (vs->s_svr && vs->s_svr->alive && vs->s_svr->reloaded && vs->s_svr->set) {
if (vs->s_svr && vs->s_svr->reloaded && vs->s_svr->set) {
ipvs_set_drule(IP_VS_SO_SET_ADDDEST, &drule, vs->s_svr);
drule.user.weight = vs->s_svr->alive ? real_weight(vs->s_svr->effective_weight) : 0;

if (vs->s_svr->forwarding_method != IP_VS_CONN_F_MASQ)
drule.user.port = inet_sockaddrport(&vsge->addr);
Expand Down Expand Up @@ -733,7 +734,7 @@ ipvs_group_remove_entry(virtual_server_t *vs, virtual_server_group_entry_t *vsge

/* Process realserver queue */
list_for_each_entry(rs, &vs->rs, e_list) {
if (rs->alive) {
if (rs->set) {
if (global_data->lvs_flush_on_stop == LVS_NO_FLUSH) {
/* Setting IPVS drule */
ipvs_set_drule(IP_VS_SO_SET_DELDEST, &drule, rs);
Expand All @@ -756,7 +757,7 @@ ipvs_group_remove_entry(virtual_server_t *vs, virtual_server_group_entry_t *vsge
}
}

if (vs->s_svr && vs->s_svr->alive && vs->s_svr->set) {
if (vs->s_svr && vs->s_svr->set) {
if (global_data->lvs_flush_on_stop == LVS_NO_FLUSH) {
ipvs_set_drule(IP_VS_SO_SET_ADDDEST, &drule, vs->s_svr);

Expand Down
62 changes: 40 additions & 22 deletions keepalived/check/ipwrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -1009,8 +1009,12 @@ migrate_checkers(virtual_server_t *vs, real_server_t *old_rs, real_server_t *new
dummy_checker.vs = vs;
dummy_checker.rs = new_rs;
perform_svr_state(true, &dummy_checker);
} else if (new_rs->num_failed_checkers && new_rs->set != new_rs->inhibit)
} else if (new_rs->num_failed_checkers && new_rs->set != new_rs->inhibit) {
/* ipvs_cmd() checks for alive rather than set */
new_rs->alive = new_rs->set;
ipvs_cmd(new_rs->inhibit ? IP_VS_SO_SET_ADDDEST : IP_VS_SO_SET_DELDEST, vs, new_rs);
new_rs->alive = false;
}
}

/* Clear the diff rs of the old vs */
Expand Down Expand Up @@ -1074,32 +1078,46 @@ clear_diff_rs(virtual_server_t *old_vs, virtual_server_t *new_vs)

/* clear sorry server, but only if changed */
static void
clear_diff_s_srv(virtual_server_t *old_vs, real_server_t *new_rs)
clear_diff_s_srv(virtual_server_t *old_vs, virtual_server_t *new_vs)
{
real_server_t *old_rs = old_vs->s_svr;
real_server_t *old_ss = old_vs->s_svr;
real_server_t *new_ss = new_vs->s_svr;
bool reinstate_alive_rs;

if (!old_rs)
if (!old_ss)
return;

if (new_rs && rs_iseq(old_rs, new_rs)) {
if (new_ss && rs_iseq(old_ss, new_ss)) {
/* which fields are really used on s_svr? */
new_rs->alive = old_rs->alive;
new_rs->set = old_rs->set;
new_rs->effective_weight = new_rs->iweight;
new_rs->reloaded = true;
new_ss->alive = old_ss->alive;
new_ss->set = old_ss->set;
new_ss->effective_weight = new_ss->iweight;
new_ss->reloaded = true;

if (old_ss->inhibit == new_ss->inhibit ||
old_ss->alive)
return;
}
else {
if (old_rs->inhibit) {
if (!ISALIVE(old_rs) && old_rs->set)
SET_ALIVE(old_rs);
old_rs->inhibit = false;
}
if (ISALIVE(old_rs)) {
log_message(LOG_INFO, "Removing sorry server %s from VS %s"
, FMT_RS(old_rs, old_vs)
, FMT_VS(old_vs));
ipvs_cmd(LVS_CMD_DEL_DEST, old_vs, old_rs);
}

/* With no sorry server configured, any alive real servers
* need to be reinstated. */
reinstate_alive_rs = old_ss->alive && !new_ss;

if (old_ss->inhibit && !ISALIVE(old_ss)) {
/* Force removing the old SS */
SET_ALIVE(old_ss);
old_ss->inhibit = false;
}

if (ISALIVE(old_ss)) {
log_message(LOG_INFO, "Removing sorry server %s from VS %s"
, FMT_RS(old_ss, old_vs)
, FMT_VS(old_vs));
ipvs_cmd(LVS_CMD_DEL_DEST, old_vs, old_ss);
new_ss->set = false;

if (reinstate_alive_rs)
perform_quorum_state(new_vs, true);
}
}

Expand Down Expand Up @@ -1151,7 +1169,7 @@ clear_diff_services(void)

vs->omega = true;
clear_diff_rs(vs, new_vs);
clear_diff_s_srv(vs, new_vs->s_svr);
clear_diff_s_srv(vs, new_vs);

update_alive_counts(vs, new_vs);
}
Expand Down

0 comments on commit 967fcf0

Please sign in to comment.