Hi, I would like to virtualize carp(4) variables to have per vnet control.
Any comments, objections? -- Mikolaj Golub
commit 646e0b161ae7782259335cec652e178652ed7af3 Author: Mikolaj Golub <troc...@freebsd.org> Date: Tue Aug 6 23:47:31 2013 +0300 Virtualize carp(4) variables for per vnet control. diff --git a/sys/netinet/ip_carp.c b/sys/netinet/ip_carp.c index 9228a8f..2ac39b7 100644 --- a/sys/netinet/ip_carp.c +++ b/sys/netinet/ip_carp.c @@ -187,28 +187,47 @@ static int proto_reg[] = {-1, -1}; * dereferencing our function pointers. */ -static int carp_allow = 1; /* Accept incoming CARP packets. */ -static int carp_preempt = 0; /* Preempt slower nodes. */ -static int carp_log = 1; /* Log level. */ -static int carp_demotion = 0; /* Global advskew demotion. */ -static int carp_senderr_adj = CARP_MAXSKEW; /* Send error demotion factor */ -static int carp_ifdown_adj = CARP_MAXSKEW; /* Iface down demotion factor */ +/* Accept incoming CARP packets. */ +static VNET_DEFINE(int, carp_allow) = 1; +#define V_carp_allow VNET(carp_allow) + +/* Preempt slower nodes. */ +static VNET_DEFINE(int, carp_preempt) = 0; +#define V_carp_preempt VNET(carp_preempt) + +/* Log level. */ +static VNET_DEFINE(int, carp_log) = 1; +#define V_carp_log VNET(carp_log) + +/* Global advskew demotion. */ +static VNET_DEFINE(int, carp_demotion) = 0; +#define V_carp_demotion VNET(carp_demotion) + +/* Send error demotion factor. */ +static VNET_DEFINE(int, carp_senderr_adj) = CARP_MAXSKEW; +#define V_carp_senderr_adj VNET(carp_senderr_adj) + +/* Iface down demotion factor. */ +static VNET_DEFINE(int, carp_ifdown_adj) = CARP_MAXSKEW; +#define V_carp_ifdown_adj VNET(carp_ifdown_adj) + static int carp_demote_adj_sysctl(SYSCTL_HANDLER_ARGS); SYSCTL_NODE(_net_inet, IPPROTO_CARP, carp, CTLFLAG_RW, 0, "CARP"); -SYSCTL_INT(_net_inet_carp, OID_AUTO, allow, CTLFLAG_RW, &carp_allow, 0, - "Accept incoming CARP packets"); -SYSCTL_INT(_net_inet_carp, OID_AUTO, preempt, CTLFLAG_RW, &carp_preempt, 0, - "High-priority backup preemption mode"); -SYSCTL_INT(_net_inet_carp, OID_AUTO, log, CTLFLAG_RW, &carp_log, 0, - "CARP log level"); -SYSCTL_PROC(_net_inet_carp, OID_AUTO, demotion, CTLTYPE_INT|CTLFLAG_RW, +SYSCTL_VNET_INT(_net_inet_carp, OID_AUTO, allow, CTLFLAG_RW, + &VNET_NAME(carp_allow), 0, "Accept incoming CARP packets"); +SYSCTL_VNET_INT(_net_inet_carp, OID_AUTO, preempt, CTLFLAG_RW, + &VNET_NAME(carp_preempt), 0, "High-priority backup preemption mode"); +SYSCTL_VNET_INT(_net_inet_carp, OID_AUTO, log, CTLFLAG_RW, + &VNET_NAME(carp_log), 0, "CARP log level"); +SYSCTL_VNET_PROC(_net_inet_carp, OID_AUTO, demotion, CTLTYPE_INT|CTLFLAG_RW, 0, 0, carp_demote_adj_sysctl, "I", "Adjust demotion factor (skew of advskew)"); -SYSCTL_INT(_net_inet_carp, OID_AUTO, senderr_demotion_factor, CTLFLAG_RW, - &carp_senderr_adj, 0, "Send error demotion factor adjustment"); -SYSCTL_INT(_net_inet_carp, OID_AUTO, ifdown_demotion_factor, CTLFLAG_RW, - &carp_ifdown_adj, 0, "Interface down demotion factor adjustment"); +SYSCTL_VNET_INT(_net_inet_carp, OID_AUTO, senderr_demotion_factor, CTLFLAG_RW, + &VNET_NAME(carp_senderr_adj), 0, "Send error demotion factor adjustment"); +SYSCTL_VNET_INT(_net_inet_carp, OID_AUTO, ifdown_demotion_factor, CTLFLAG_RW, + &VNET_NAME(carp_ifdown_adj), 0, + "Interface down demotion factor adjustment"); static counter_u64_t carpstats[sizeof(struct carpstats) / sizeof(uint64_t)]; #define CARPSTATS_ADD(name, val) \ @@ -251,12 +270,12 @@ SYSCTL_PROC(_net_inet_carp, OID_AUTO, stats, CTLTYPE_OPAQUE | CTLFLAG_RW, } while (0) #define CARP_LOG(...) do { \ - if (carp_log > 0) \ + if (V_carp_log > 0) \ log(LOG_INFO, "carp: " __VA_ARGS__); \ } while (0) #define CARP_DEBUG(...) do { \ - if (carp_log > 1) \ + if (V_carp_log > 1) \ log(LOG_DEBUG, __VA_ARGS__); \ } while (0) @@ -277,8 +296,8 @@ SYSCTL_PROC(_net_inet_carp, OID_AUTO, stats, CTLTYPE_OPAQUE | CTLFLAG_RW, TAILQ_FOREACH((sc), &(ifp)->if_carp->cif_vrs, sc_list) #define DEMOTE_ADVSKEW(sc) \ - (((sc)->sc_advskew + carp_demotion > CARP_MAXSKEW) ? \ - CARP_MAXSKEW : ((sc)->sc_advskew + carp_demotion)) + (((sc)->sc_advskew + V_carp_demotion > CARP_MAXSKEW) ? \ + CARP_MAXSKEW : ((sc)->sc_advskew + V_carp_demotion)) static void carp_input_c(struct mbuf *, struct carp_header *, sa_family_t); static struct carp_softc @@ -430,7 +449,7 @@ carp_input(struct mbuf *m, int hlen) CARPSTATS_INC(carps_ipackets); - if (!carp_allow) { + if (!V_carp_allow) { m_freem(m); return; } @@ -513,7 +532,7 @@ carp6_input(struct mbuf **mp, int *offp, int proto) CARPSTATS_INC(carps_ipackets6); - if (!carp_allow) { + if (!V_carp_allow) { m_freem(m); return (IPPROTO_DONE); } @@ -647,7 +666,7 @@ carp_input_c(struct mbuf *m, struct carp_header *ch, sa_family_t af) * If we're pre-empting masters who advertise slower than us, * and this one claims to be slower, treat him as down. */ - if (carp_preempt && timevalcmp(&sc_tv, &ch_tv, <)) { + if (V_carp_preempt && timevalcmp(&sc_tv, &ch_tv, <)) { CARP_LOG("VHID %u@%s: BACKUP -> MASTER " "(preempting a slower master)\n", sc->sc_vhid, @@ -830,13 +849,14 @@ carp_send_ad_locked(struct carp_softc *sc) if (sc->sc_sendad_errors < INT_MAX) sc->sc_sendad_errors++; if (sc->sc_sendad_errors == CARP_SENDAD_MAX_ERRORS) - carp_demote_adj(carp_senderr_adj, "send error"); + carp_demote_adj(V_carp_senderr_adj, + "send error"); sc->sc_sendad_success = 0; } else { if (sc->sc_sendad_errors >= CARP_SENDAD_MAX_ERRORS) { if (++sc->sc_sendad_success >= CARP_SENDAD_MIN_SUCCESS) { - carp_demote_adj(-carp_senderr_adj, + carp_demote_adj(-V_carp_senderr_adj, "send ok"); sc->sc_sendad_errors = 0; } @@ -903,14 +923,14 @@ carp_send_ad_locked(struct carp_softc *sc) if (sc->sc_sendad_errors < INT_MAX) sc->sc_sendad_errors++; if (sc->sc_sendad_errors == CARP_SENDAD_MAX_ERRORS) - carp_demote_adj(carp_senderr_adj, + carp_demote_adj(V_carp_senderr_adj, "send6 error"); sc->sc_sendad_success = 0; } else { if (sc->sc_sendad_errors >= CARP_SENDAD_MAX_ERRORS) { if (++sc->sc_sendad_success >= CARP_SENDAD_MIN_SUCCESS) { - carp_demote_adj(-carp_senderr_adj, + carp_demote_adj(-V_carp_senderr_adj, "send6 ok"); sc->sc_sendad_errors = 0; } @@ -1541,7 +1561,7 @@ carp_destroy(struct carp_softc *sc) CARP_LOCK(sc); if (sc->sc_suppress) - carp_demote_adj(-carp_ifdown_adj, "vhid removed"); + carp_demote_adj(-V_carp_ifdown_adj, "vhid removed"); callout_drain(&sc->sc_ad_tmo); #ifdef INET callout_drain(&sc->sc_md_tmo); @@ -2006,13 +2026,13 @@ carp_sc_state(struct carp_softc *sc) carp_set_state(sc, INIT); carp_setrun(sc, 0); if (!sc->sc_suppress) - carp_demote_adj(carp_ifdown_adj, "interface down"); + carp_demote_adj(V_carp_ifdown_adj, "interface down"); sc->sc_suppress = 1; } else { carp_set_state(sc, INIT); carp_setrun(sc, 0); if (sc->sc_suppress) - carp_demote_adj(-carp_ifdown_adj, "interface up"); + carp_demote_adj(-V_carp_ifdown_adj, "interface up"); sc->sc_suppress = 0; } } @@ -2020,8 +2040,8 @@ carp_sc_state(struct carp_softc *sc) static void carp_demote_adj(int adj, char *reason) { - atomic_add_int(&carp_demotion, adj); - CARP_LOG("demoted by %d to %d (%s)\n", adj, carp_demotion, reason); + atomic_add_int(&V_carp_demotion, adj); + CARP_LOG("demoted by %d to %d (%s)\n", adj, V_carp_demotion, reason); taskqueue_enqueue(taskqueue_swi, &carp_sendall_task); } @@ -2030,7 +2050,7 @@ carp_demote_adj_sysctl(SYSCTL_HANDLER_ARGS) { int new, error; - new = carp_demotion; + new = V_carp_demotion; error = sysctl_handle_int(oidp, &new, 0, req); if (error || !req->newptr) return (error);
_______________________________________________ freebsd-virtualization@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-virtualization To unsubscribe, send any mail to "freebsd-virtualization-unsubscr...@freebsd.org"