32.4. Fencing and Exclusive Resource Ownership

Fencing is the mechanism that turns "we cannot hear that node" into "that node cannot write". Without it, every failover rests on an assumption.

32.4.1. Why Membership Loss Does Not Prove a Node Has Stopped

Corosync declares a node lost when messages stop arriving. That is a statement about communication, not about the node. The same silence covers a node that crashed completely, a node whose cluster link failed while the service network still works, a kernel wedged in uninterruptible I/O with nfsd still draining writes, and a node paused by its hypervisor with memory intact and intentions unchanged.

If the cluster reacts to silence by starting the service elsewhere, the still-alive-but-silent case produces two active owners: two DRBD primaries, two mounted copies, two NFS servers answering one address. The data divergence that follows is the worst outcome a high-availability system can produce, because it is silent - both servers look healthy, and the corruption is discovered only when the copies are next compared.

The remedy is fencing: an action, taken through a channel that does not depend on the fenced node's cooperation, that guarantees the node cannot write. Pacemaker's historical name for it is STONITH - "shoot the other node in the head" - and the colorful name encodes the rule: verify exclusion, do not infer it. A fence action must succeed before the cluster reassigns writable resources, and if it cannot succeed, the cluster's correct behavior is to leave the service down rather than gamble on the silent node's good behavior.

32.4.2. STONITH Devices, Watchdogs, and SBD Design Choices

A fencing device is anything that can stop a node without asking it. The agents shipped with the installed packages cover the common classes. On ha1, as john:

$ sudo stonith_admin --list-installed
apcmaster
apcmastersnmp
apcsmart
baytech
bladehpi
cyclades
drac3
external/drac5
external/dracmc-telnet
external/hetzner
external/hmchttp
external/ibmrsa
external/ibmrsa-telnet
external/ipmi
external/ippower9258
external/kdumpcheck
external/libvirt
external/nut
external/rackpdu
external/riloe
external/sbd
external/ssh
external/vcenter
external/vmware
external/xen0
external/xen0-ha
ibmhmc
ipmilan
meatware
null
nw_rpc100s
rcd_serial
rps10
ssh
suicide
wti_mpc
wti_nps
fence_legacy
fence_watchdog
39 fence devices found

The list divides naturally into classes:

Class Example agents Channel Notes
Management controller ipmilan, external/ipmi, external/drac5, external/ibmrsa BMC/DRAC/iLO network The default choice for physical servers; independent of the node's OS
Power distribution external/nut, external/rackpdu, wti_mpc, apcsmart PDU or UPS network port Cuts power at the feed; mind which outlet feeds which node
Hypervisor external/libvirt, external/vmware, external/xen0-ha Hypervisor API Resets a guest from the host; the hypervisor becomes the fence channel
Shared storage message external/sbd Shared block device SBD, described below; the fence travels on storage, not the network
Watchdog fence_watchdog, suicide Local hardware timer Self-fencing only; used alone it proves less than it appears to

SBD (STONITH Block Device) is worth understanding even where it is not used, because it decouples fencing from management controllers. Each node runs the sbd daemon, which watches a message slot reserved for it on a shared block device - a small SAN LUN, an iSCSI LUN visible to all nodes, or, with diskless SBD, no device at all. To fence node 2, any node writes a fence message into node 2's slot; node 2's own daemon reads it and hands its watchdog the poisoned verdict, and the hardware watchdog reboots the machine. Fencing authority thus rides on shared storage, which the nodes must keep anyway, rather than on a second management network. Diskless SBD drops the shared disk and arms the watchdog directly on quorum loss, on the loss of a monitored daemon, or on a Pacemaker fencing decision - a node that cannot stay in contact with a quorate peer removes itself.

The practice cluster has the sbd package installed but unconfigured:

$ sudo systemctl is-active sbd
inactive

The exit status is 3 (inactive). Configuring it would mean either a shared device (crm cluster init -s /dev/... writes /etc/default/sbd and the cluster property) or the diskless form (-S, plus -w to select a watchdog such as softdog). The captured CIB in section 32.6.3 shows the resulting cluster property have-watchdog=false, which is Pacemaker recording that no watchdog-backed fencing is in use.

The watchdog itself deserves a sentence: /dev/watchdog is a kernel interface to a hardware (or softdog software) timer that reboots the machine unless userspace keeps petting it. That property - reboot on silence - is exactly what fencing needs, and it is also what makes a watchdog-only fence agent weaker than it sounds: a node that is wedged badly enough to ignore its slot may also be wedged badly enough to miss its watchdog deadline, which is fine, but a node that is merely partitioned while otherwise healthy will not self-fence through a watchdog unless something arms it. Arming is the cluster's job, and only shared-storage SBD or equivalent does it reliably.

32.4.3. Fencing Virtual Machines and Physical Hosts

For virtual machines, the hypervisor is the out-of-band channel. The external/libvirt agent resets a guest domain through a libvirt URI, and its metadata shows the two parameters that matter. Selected output, on ha1, as john:

$ sudo crm ra info stonith:external/libvirt
stonith:external/libvirt - libvirt STONITH device

libvirt-based host reset for Xen/KVM guest domain through hypervisor

## Parameters (*: required, []: default):

hostlist* (string): List of hostname[:domain_id]..
    List of controlled hosts: hostname[:domain_id]..
    The optional domain_id defaults to the hostname.

hypervisor_uri* (string): Hypervisor URI
    URI for connection to the hypervisor.
    driver[+transport]://[username@][hostlist][:port]/[path][?extraparameters]
    e.g.
    qemu+ssh://my_kvm_server.mydomain.my/system   (uses ssh for root)
    xen://my_kvm_server.mydomain.my/              (uses TLS for client)

    virsh must be installed (e.g. libvir-client package) and access control must
    be configured for your selected URI.

pcmk_action_limit (integer, [1]): The maximum number of actions can be performed in parallel on this device
    If the concurrent-fencing cluster property is "true", this specifies the maximum number of actions that can be performed in parallel on this device. A value of -1 means unlimited.

pcmk_delay_base (string, [0s]): Enable a base delay for fencing actions and specify base delay value.
    This enables a static delay for fencing actions, which can help avoid "death matches" where two nodes try to fence each other at the same time. If pcmk_delay_max is also used, a random delay will be added such that the total delay is kept below that value. This can be set to a single time value to apply to any node targeted by this device (useful if a separate device is configured for each target), or to a node map (for example, "node1:1s;node2:5") to set a different value for each target.

The output continues with pcmk_delay_max, which bounds the total randomized delay, and the standard Pacemaker fencing parameters. The entries shown are the essential ones for this agent: a guest named ha2 is fenced by connecting to the hypervisor and resetting the domain named ha2. Two practical requirements follow from the design. First, the fencing node needs a libvirt connection to the hypervisor - qemu+ssh:// with root SSH trust is the usual mechanism, and the same SSH trust discipline from Chapter 20 applies. Second, the hypervisor is now a shared failure domain for the guests: it is the fence authority and the host. For a real two-node HA pair, the guests must live on different physical hosts, and each guest is then fenced through the other guest's host - never through a host it shares fate with.

For physical hosts, the management controller class is the baseline: nearly every server ships a BMC reachable by IPMI, and the ipmilan agent drives it with the node's BMC address and credentials. Power PDU agents are the fallback for hardware whose BMC is unreliable. Both share the same requirement as the libvirt agent: the fencing node must reach the device through a path that does not involve the fenced node, and the device credentials must live in the CIB - which makes CIB file permissions and CIB backups security-relevant in a way ordinary cluster configuration is not (Chapter 26 covers credential handling generally).

32.4.4. Verifying Isolation Before Reassigning Writable Storage

Pacemaker enforces the fence-before-recover order at the configuration level, and it refuses to run unfenced when fencing is claimed but not configured. The practice cluster demonstrates the refusal directly. On ha1, as john, with no fence device configured:

$ sudo crm configure property stonith-enabled=true
error: Resource start-up disabled since no STONITH resources have been defined
error: Either configure some or disable STONITH with the stonith-enabled option
error: NOTE: Clusters with shared data need STONITH to ensure data integrity
error: CIB did not pass schema validation
Configuration invalid (with errors)

The command fails, and the CIB is unchanged. Turning fencing on is therefore not a property flip; it is the act of configuring a real device. Conversely, disabling it produces a warning that is worth reading in the cluster's own voice - as captured when the walkthrough sets the property in section 32.6.3:

$ sudo crm configure property stonith-enabled=false
(unpack_config)     warning: Blind faith: not fencing unseen nodes

"Blind faith" is precisely the design statement this section has been making, and the practice cluster makes it deliberately: the practice hosts expose no management controller, PDU, or hypervisor API reachable from inside them, so fencing cannot be exercised there. The cluster runs unfenced, and the unplanned failure test (section 32.3.5) is safe only because the isolation it creates leaves the data-owning node in the majority. A production cluster with writable state must instead configure a fence device and let the error message above be impossible to produce.

Once fencing is configured, the verification loop is: the monitor fails or membership drops; Pacemaker selects a fence device for the lost node and runs it; only a successful fence result allows recovery to proceed; the pacemaker journal records the action, and the failed node's management path confirms it is down. The last step - looking at the node, not just at the cluster - is the operational habit that catches fence devices that report success without effect.

32.4.5. Fencing Failures, Recovery Loops, and Rejoining a Node

Fencing can fail: the BMC is unreachable, the PDU outlet was relabeled, the hypervisor connection was revoked. Pacemaker's behavior in that case is conservative and correct - with fencing enabled, a node whose fence cannot be confirmed is never assumed fenced. The cluster retries the fence according to the device's action timeout, and while the fence is unconfirmed it does not start the lost node's resources elsewhere. A cluster that cannot fence is a cluster that refuses to fail over, which is the right refusal: the alternative is a second writer. The operational response is to repair the fence path, not to disable fencing.

Two symmetric failures deserve one configuration habit. When both nodes decide simultaneously that the other is dead, each fences the other - a "death match" in which the surviving node depends on timing. The agent metadata above shows the standard mitigation: pcmk_delay_base and pcmk_delay_max inject a per-node delay (fixed or randomized) into fence actions so simultaneous mutual fencing does not deterministically kill both. Set a small delay on any two-node pair; it costs seconds and removes a race.

A fenced node that reboots is not broken; it is returning. On rejoin it re-authenticates with Corosync, Pacemaker integrates it with its resources stopped, and DRBD reconnects and resynchronizes as Chapter 31 showed in detail. The captured recovery in section 32.3.5 is the model: ha1 returns as Unpromoted with the group untouched on ha2, no manual cleanup, no resource movement. If the node failed while holding a resource, its failure counts may need clearing once the fault is fixed - crm resource cleanup resets them so a healthy node is not permanently banned by its history. The fencing-failure and death-match paths are documented behavior of Pacemaker's fencing stack (pacemaker(7), stonith(8)); they are not exercised in this chapter's practice cluster, which runs unfenced, and the difference is stated here once rather than repeated at each procedure.