On Mon, Aug 12, 2013 at 02:16:15PM +0400, Gleb Smirnoff wrote:
> On Sun, Aug 11, 2013 at 11:08:35PM +0300, Mikolaj Golub wrote:
> M> Hi,
> M>
> M> I would like to virtualize carp(4) variables to have per vnet control.
> M>
> M> Any comments, objections?
>
> No objections!
Andrey pointed out (on irc) that carpstats was missing virtualization
too. Here is an updated patch.
--
Mikolaj Golub
commit ac71429a70862ca75a614bb798dcfb62e67faca3
Author: Mikolaj Golub
Date: Tue Aug 6 23:47:31 2013 +0300
Virtualize carp(4) variables to have per vnet control.
diff --git a/sys/netinet/ip_carp.c b/sys/netinet/ip_carp.c
index 9228a8f..436385d 100644
--- a/sys/netinet/ip_carp.c
+++ b/sys/netinet/ip_carp.c
@@ -187,48 +187,59 @@ 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");
+
+VNET_PCPUSTAT_DEFINE(struct carpstats, carpstats);
+VNET_PCPUSTAT_SYSINIT(carpstats);
+VNET_PCPUSTAT_SYSUNINIT(carpstats);
-static counter_u64_t carpstats[sizeof(struct carpstats) / sizeof(uint64_t)];
#define CARPSTATS_ADD(name, val) \
-counter_u64_add(carpstats[offsetof(struct carpstats, name) / \
+counter_u64_add(VNET(carpstats)[offsetof(struct carpstats, name) / \
sizeof(uint64_t)], (val))
#define CARPSTATS_INC(name) CARPSTATS_ADD(name, 1)
-static int
-carpstats_sysctl(SYSCTL_HANDLER_ARGS)
-{
- struct carpstats s;
-
- COUNTER_ARRAY_COPY(carpstats, &s, sizeof(s) / sizeof(uint64_t));
- if (req->newptr)
- COUNTER_ARRAY_ZERO(carpstats, sizeof(s) / sizeof(uint64_t));
- return (SYSCTL_OUT(req, &s, sizeof(s)));
-}
-SYSCTL_PROC(_net_inet_carp, OID_AUTO, stats, CTLTYPE_OPAQUE | CTLFLAG_RW,
-NULL, 0, carpstats_sysctl, "I",
-"CARP statistics (struct carpstats, netinet/ip_carp.h)");
+SYSCTL_VNET_PCPUSTAT(_net_inet_carp, OID_AUTO, stats, struct carpstats,
+carpstats, "CARP statistics (struct carpstats, netinet/ip_carp.h)");
#define CARP_LOCK_INIT(sc) mtx_init(&(sc)->sc_mtx, "carp_softc", \
NULL, MTX_DEF)
@@ -251,12 +262,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_