carp: Lock MPSAFE, step 10 of 11
authorSepherosa Ziehau <sephe@dragonflybsd.org>
Mon, 9 Apr 2012 13:06:57 +0000 (21:06 +0800)
committerSepherosa Ziehau <sephe@dragonflybsd.org>
Tue, 10 Apr 2012 13:28:34 +0000 (21:28 +0800)
commitbb05f5cdc30aad020abec4b2b54773a045f4ac27
tree302111974d4cf8a70140390e5b45d52854b2dbcf
parentf516173c52491b80046d64c24a8b6a5fa8b466c6
carp: Lock MPSAFE, step 10 of 11

Make carp_softc.sc_carpdev and ifnet.if_carp accessing and updating
lockless MPSAFE.

carp_softc.sc_carpdev:
- Reader of the sc_carpdev will cache the value in temporary variable
  and use the cached value instead of always accessing sc_carpdev,
  which may be inconsistent due to change of sc_carpdev.

ifnet.if_carp
- if_carp is a pointer to the carp_softc container list, while the list
  only contains pointer to carp_softc
- Reader of if_carp will cache the value in temporary variable and use
  the cached value instead of always accessing if_carp, which may be
  inconsistent due to if_carp updating.
- Updating of the if_carp is done in the following way:
    ocif = ifp->if_carp;
    ncif = cif_copy(ocif);
    cif_modify(ncif);
    ifp->if_carp = ncif;
    netmsg_service_sync();
    /* when we reach here all users of old if_carp (ocif) are done */
    cif_free(ocif)
sys/net/if_ethersubr.c
sys/netinet/ip_carp.c
sys/netinet/ip_carp.h