History log of /freebsd-current/sys/cam/ctl/ctl_ha.c
Revision Date Author Comments
# 0d378958 23-May-2024 Gleb Smirnoff <glebius@FreeBSD.org>

ctl: use socket buffer mutexes in struct socket directly

A mechanical change performed with sed(1) script:

s/SOCKBUF_LOCK\(&so->so_rcv\)/SOCK_RECVBUF_LOCK(so)/
s/SOCKBUF_UNLOCK\(&so->so_rcv\)/SOCK_RECVBUF_UNLOCK(so)/
s/SOCKBUF_MTX\(&so->so_rcv\)/SOCK_RECVBUF_MTX(so)/
s/SOCKBUF_LOCK\(&so->so_snd\)/SOCK_SENDBUF_LOCK(so)/
s/SOCKBUF_UNLOCK\(&so->so_snd\)/SOCK_SENDBUF_UNLOCK(so)/
s/SOCKBUF_MTX\(&so->so_snd\)/SOCK_SENDBUF_MTX(so)/

Reviewed by: mav
Differential Revision: https://reviews.freebsd.org/D45190


# cfb1e929 30-Nov-2023 Gleb Smirnoff <glebius@FreeBSD.org>

sockets: don't malloc/free sockaddr memory on accept(2)

Let the accept functions provide stack memory for protocols to fill it in.
Generic code should provide sockaddr_storage, specialized code may provide
smaller structure.

While rewriting accept(2) make 'addrlen' a true in/out parameter, reporting
required length in case if provided length was insufficient. Our manual
page accept(2) and POSIX don't explicitly require that, but one can read
the text as they do. Linux also does that. Update tests accordingly.

Reviewed by: rscheff, tuexen, zlei, dchagin
Differential Revision: https://reviews.freebsd.org/D42635


# 9d61fd08 23-Nov-2023 Mitchell Horne <mhorne@FreeBSD.org>

ctl_ha: don't shutdown threads if scheduler is stopped

In this case, just return.

Reviewed by: markj
MFC after: 1 week
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D42341


# 2ffd30f7 06-Nov-2023 Warner Losh <imp@FreeBSD.org>

cam: Remove left-over sys/cdefs.h in sys/cam

These weren't removed when $FreeBSD$ was removed. They aren't needed and
now are a style(9) nonconformity.

Sponsored by: Netflix


# 685dc743 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

sys: Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 4d846d26 10-May-2023 Warner Losh <imp@FreeBSD.org>

spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD

The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with: pfg
MFC After: 3 days
Sponsored by: Netflix


# 303477d3 10-Aug-2021 Alexander Motin <mav@FreeBSD.org>

cam(4): Mark all sysctls as CTLFLAG_MPSAFE.

This code does not use Giant lock for very long time.

MFC after: 2 weeks


# 27dcd3d9 01-Sep-2020 Mateusz Guzik <mjg@FreeBSD.org>

cam: clean up empty lines in .c and .h files


# 3873b149 26-May-2020 Alexander Motin <mav@FreeBSD.org>

Fix fallout of r319722 in CTL HA.

ha_lso is a listening socket (unless bind() has failed), so should use
solisten_upcall_set(NULL, NULL), not soupcall_clear().

MFC after: 1 week
Sponsored by: iXsystems, Inc.


# fd10265c 26-May-2020 Alexander Motin <mav@FreeBSD.org>

Do not remove upcall if we haven't yet.

This fixes assertion if we failed to bind listening HA socket.

MFC after: 1 week
Sponsored by: iXsystems, Inc.


# 51447e49 01-Mar-2020 Warner Losh <imp@FreeBSD.org>

Remove pre-FreeBSD 11 compat code.


# 7029da5c 26-Feb-2020 Pawel Biernacki <kaktus@FreeBSD.org>

Mark more nodes as CTLFLAG_MPSAFE or CTLFLAG_NEEDGIANT (17 of many)

r357614 added CTLFLAG_NEEDGIANT to make it easier to find nodes that are
still not MPSAFE (or already are but aren’t properly marked).
Use it in preparation for a general review of all nodes.

This is non-functional change that adds annotations to SYSCTL_NODE and
SYSCTL_PROC nodes using one of the soon-to-be-required flags.

Mark all obvious cases as MPSAFE. All entries that haven't been marked
as MPSAFE before are by default marked as NEEDGIANT

Approved by: kib (mentor, blanket)
Commented by: kib, gallatin, melifaro
Differential Revision: https://reviews.freebsd.org/D23718


# e2e050c8 19-May-2019 Conrad Meyer <cem@FreeBSD.org>

Extract eventfilter declarations to sys/_eventfilter.h

This allows replacing "sys/eventfilter.h" includes with "sys/_eventfilter.h"
in other header files (e.g., sys/{bus,conf,cpu}.h) and reduces header
pollution substantially.

EVENTHANDLER_DECLARE and EVENTHANDLER_LIST_DECLAREs were moved out of .c
files into appropriate headers (e.g., sys/proc.h, powernv/opal.h).

As a side effect of reduced header pollution, many .c files and headers no
longer contain needed definitions. The remainder of the patch addresses
adding appropriate includes to fix those files.

LOCK_DEBUG and LOCK_FILE_LINE_ARG are moved to sys/_lock.h, as required by
sys/mutex.h since r326106 (but silently protected by header pollution prior
to this change).

No functional change (intended). Of course, any out of tree modules that
relied on header pollution for sys/eventhandler.h, sys/lock.h, or
sys/mutex.h inclusion need to be fixed. __FreeBSD_version has been bumped.


# f24882ec 16-Jan-2018 Pedro F. Giffuni <pfg@FreeBSD.org>

SPDX: finish tagging sys/cam.


# 779f106a 08-Jun-2017 Gleb Smirnoff <glebius@FreeBSD.org>

Listening sockets improvements.

o Separate fields of struct socket that belong to listening from
fields that belong to normal dataflow, and unionize them. This
shrinks the structure a bit.
- Take out selinfo's from the socket buffers into the socket. The
first reason is to support braindamaged scenario when a socket is
added to kevent(2) and then listen(2) is cast on it. The second
reason is that there is future plan to make socket buffers pluggable,
so that for a dataflow socket a socket buffer can be changed, and
in this case we also want to keep same selinfos through the lifetime
of a socket.
- Remove struct struct so_accf. Since now listening stuff no longer
affects struct socket size, just move its fields into listening part
of the union.
- Provide sol_upcall field and enforce that so_upcall_set() may be called
only on a dataflow socket, which has buffers, and for listening sockets
provide solisten_upcall_set().

o Remove ACCEPT_LOCK() global.
- Add a mutex to socket, to be used instead of socket buffer lock to lock
fields of struct socket that don't belong to a socket buffer.
- Allow to acquire two socket locks, but the first one must belong to a
listening socket.
- Make soref()/sorele() to use atomic(9). This allows in some situations
to do soref() without owning socket lock. There is place for improvement
here, it is possible to make sorele() also to lock optionally.
- Most protocols aren't touched by this change, except UNIX local sockets.
See below for more information.

o Reduce copy-and-paste in kernel modules that accept connections from
listening sockets: provide function solisten_dequeue(), and use it in
the following modules: ctl(4), iscsi(4), ng_btsocket(4), ng_ksocket(4),
infiniband, rpc.

o UNIX local sockets.
- Removal of ACCEPT_LOCK() global uncovered several races in the UNIX
local sockets. Most races exist around spawning a new socket, when we
are connecting to a local listening socket. To cover them, we need to
hold locks on both PCBs when spawning a third one. This means holding
them across sonewconn(). This creates a LOR between pcb locks and
unp_list_lock.
- To fix the new LOR, abandon the global unp_list_lock in favor of global
unp_link_lock. Indeed, separating these two locks didn't provide us any
extra parralelism in the UNIX sockets.
- Now call into uipc_attach() may happen with unp_link_lock hold if, we
are accepting, or without unp_link_lock in case if we are just creating
a socket.
- Another problem in UNIX sockets is that uipc_close() basicly did nothing
for a listening socket. The vnode remained opened for connections. This
is fixed by removing vnode in uipc_close(). Maybe the right way would be
to do it for all sockets (not only listening), simply move the vnode
teardown from uipc_detach() to uipc_close()?

Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D9770


# 4982dca1 10-Jan-2017 Alexander Motin <mav@FreeBSD.org>

Do not wait for HA thread shutdown if scheduler is stopped.

This wait loop made system hang on panic instead of reboot.

MFC after: 1 week


# f9b66e4c 05-Jan-2017 Alexander Motin <mav@FreeBSD.org>

Fix bootverbose affecting code logic in r294558.

Reported by: Jilles Tjoelker <jilles@stack.nl>


# 74b8d63d 10-Apr-2016 Pedro F. Giffuni <pfg@FreeBSD.org>

Cleanup unnecessary semicolons from the kernel.

Found with devel/coccinelle.


# 72cc9376 22-Jan-2016 Alexander Motin <mav@FreeBSD.org>

Hide "soconnect() error" messages under bootverbose.

They can be too noisy.


# 0bb9989c 25-Sep-2015 Alexander Motin <mav@FreeBSD.org>

Pass to sobind() copy of the address, not the original.


# 21d963e5 25-Sep-2015 Alexander Motin <mav@FreeBSD.org>

Remove some control_softc references.


# a85700a9 23-Sep-2015 Alexander Motin <mav@FreeBSD.org>

Make HA peers announce their parameters on connect.

HA protocol requires strict version, parameters and configuration match.
Differences there may cause full set of problems up to kernel panic.
To avoid that, validate peer parameters on connect, and abort connection
immediately if some mismatch detected.


# 59bb97a9 17-Sep-2015 Alexander Motin <mav@FreeBSD.org>

Kill HA link and shutdown the threads on shutdown.


# e2c3044b 16-Sep-2015 Alexander Motin <mav@FreeBSD.org>

Don't flap the HA link if sysctl is reset to the same value.


# 7ac58230 09-Sep-2015 Alexander Motin <mav@FreeBSD.org>

Reimplement CTL High Availability.

CTL HA functionality was originally implemented by Copan many years ago,
but large part of the sources was never published. This change includes
clean room implementation of the missing code and fixes for many bugs.

This code supports dual-node HA with ALUA in four modes:
- Active/Unavailable without interlink between nodes;
- Active/Standby with second node handling only basic LUN discovery and
reservation, synchronizing with the first node through the interlink;
- Active/Active with both nodes processing commands and accessing the
backing storage, synchronizing with the first node through the interlink;
- Active/Active with second node working as proxy, transfering all
commands to the first node for execution through the interlink.

Unlike original Copan's implementation, depending on specific hardware,
this code uses simple custom TCP-based protocol for interlink. It has
no authentication, so it should never be enabled on public interfaces.

The code may still need some polishing, but generally it is functional.

Relnotes: yes
Sponsored by: iXsystems, Inc.