drbd

package
v3.0.0-rc67 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 21 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	ConnStateStandAlone        = "StandAlone"
	ConnStateDisconnecting     = "Disconnecting"
	ConnStateUnconnected       = "Unconnected"
	ConnStateTimeout           = "Timeout"
	ConnStateBrokenPipe        = "BrokenPipe"
	ConnStateNetworkFailure    = "NetworkFailure"
	ConnStateProtocolError     = "ProtocolError"
	ConnStateTearDow           = "TearDown"
	ConnStateConnecting        = "Connecting"
	ConnStateConnected         = "Connected"
	ConnStateLegacycConnecting = "WFConnection"
)
View Source
const (
	// DiskStateUpToDate is the disk state of a replica holding the latest
	// data, the only one a promotion accepts.
	DiskStateUpToDate = "UpToDate"
)

Variables

View Source
var (
	KeyResource       = "resource "
	KeyConnectionMesh = "connection-mesh "
	KeyHosts          = "hosts "
	KeyOn             = "on "
	KeyNodeID         = "node-id "
	KeyDevice         = "device "
	KeyDisk           = "disk "
	KeyMetaDisk       = "meta-disk "
	KeyAddress        = "address "
	KeyVolume         = "volume "

	KeyResourceLen       = len(KeyResource)
	KeyConnectionMeshLen = len(KeyConnectionMesh)
	KeyHostsLen          = len(KeyHosts)
	KeyOnLen             = len(KeyOn)
	KeyNodeIDLen         = len(KeyNodeID)
	KeyDeviceLen         = len(KeyDevice)
	KeyDiskLen           = len(KeyDisk)
	KeyMetaDiskLen       = len(KeyMetaDisk)
	KeyAddressLen        = len(KeyAddress)
	KeyVolumeLen         = len(KeyVolume)

	RetryDelay   = time.Second * 1
	RetryTimeout = time.Second * 10

	ExitCodeDeviceInUse = 11

	// MaxDRBD defines the maximum number of allowable DRBD resources within the system.
	MaxDRBD = 512

	// MinPort defines the minimum port number used for a drbd resource
	MinPort = 7289

	// MaxPort defines the maximum port number used for a drbd resource
	// It is calculated as MinPort + 2 * MaxDRBD to allow other applications to use
	// the ports between MinPort and MaxPort.
	MaxPort = min(65535, MinPort+2*MaxDRBD)
)

Functions

func Dump

func Dump() ([]byte, error)

func IsCapable

func IsCapable(ctx context.Context) bool

func ResConfigFile

func ResConfigFile(res string) string

func Version

func Version(ctx context.Context) (string, error)

func WithLogger

func WithLogger(log *plog.Logger) funcopt.O

Types

type CStateM

type CStateM map[string]string

func (*CStateM) String

func (c *CStateM) String() string

type Config

type Config struct {
	XMLName   xml.Name         `xml:"config"`
	File      string           `xml:"config,attr"`
	Common    ConfigCommon     `xml:"common"`
	Resources []ConfigResource `xml:"resource"`
}

func GetConfig

func GetConfig() (*Config, error)

func ParseConfig

func ParseConfig(b []byte) (*Config, error)

func (Config) GetMinors

func (t Config) GetMinors() map[string]any

func (Config) GetPorts

func (t Config) GetPorts() map[string]any

func (Config) GetResource

func (t Config) GetResource(name string) (ConfigResource, bool)

type ConfigAddress

type ConfigAddress struct {
	XMLName xml.Name `xml:"address"`
	Family  string   `xml:"family,attr"`
	Port    string   `xml:"port,attr"`
	IP      string   `xml:",chardata"`
}

type ConfigCommon

type ConfigCommon struct {
	XMLName xml.Name `xml:"common"`
}

type ConfigConnection

type ConfigConnection struct {
	XMLName xml.Name               `xml:"connection"`
	Hosts   []ConfigConnectionHost `xml:"host"`
}

type ConfigConnectionHost

type ConfigConnectionHost struct {
	XMLName xml.Name      `xml:"host"`
	Name    string        `xml:"name,attr"`
	Address ConfigAddress `xml:"address"`
}

type ConfigDevice

type ConfigDevice struct {
	Path  string `xml:",chardata"`
	Minor string `xml:"minor,attr"`
}

type ConfigHost

type ConfigHost struct {
	Name    string         `xml:"name,attr"`
	Volumes []ConfigVolume `xml:"volume"`
	Address ConfigAddress  `xml:"address"`
}

func (ConfigHost) GetVolume

func (t ConfigHost) GetVolume(name string) (ConfigVolume, bool)

type ConfigResource

type ConfigResource struct {
	XMLName    xml.Name         `xml:"resource"`
	Name       string           `xml:"name,attr"`
	FileLine   string           `xml:"conf-file-line"`
	Hosts      []ConfigHost     `xml:"host"`
	Connection ConfigConnection `xml:"connection"`
}

func (ConfigResource) GetHost

func (t ConfigResource) GetHost(name string) (ConfigHost, bool)

type ConfigVolume

type ConfigVolume struct {
	Name     string       `xml:"vnr,attr"`
	Device   ConfigDevice `xml:"device"`
	Disk     string       `xml:"disk"`
	MetaDisk string       `xml:"meta-disk"`
}

type Digest

type Digest struct {
	Ports  map[string]any
	Minors map[string]any
}

func GetDigest

func GetDigest() (Digest, error)

func ParseDigest

func ParseDigest(b []byte) (Digest, error)

func (Digest) FreeMinor

func (t Digest) FreeMinor(exclude []int) (int, error)

func (Digest) FreePort

func (t Digest) FreePort(exclude []int) (int, error)

type DrbdShow

type DrbdShow struct {
	Resource string `json:"resource"`
	ThisHost struct {
		NodeID  int `json:"node-id"`
		Volumes []struct {
			VolumeNr    int    `json:"volume_nr"`
			DeviceMinor int    `json:"device_minor"`
			BackingDisk string `json:"backing-disk"`
			MetaDisk    string `json:"meta-disk"`
		} `json:"volumes"`
	} `json:"_this_host"`
	Connections []struct {
		Paths []struct {
			ThisHost struct {
				Address string `json:"address"`
				Port    int    `json:"port"`
				Family  string `json:"family"`
			} `json:"this_host"`
			RemoteHost struct {
				Address string `json:"address"`
				Port    int    `json:"port"`
				Family  string `json:"family"`
			} `json:"remote_host"`
		} `json:"paths"`
		Cstate string `json:"_cstate"`
		Net    struct {
			Name string `json:"_name"`
		} `json:"net"`
		Volumes []struct {
			VolumeNr int `json:"volume_nr"`
			Disk     struct {
				ResyncWithoutReplication bool `json:"resync-without-replication"`
			} `json:"disk"`
		} `json:"volumes"`
		PeerNodeID int `json:"_peer_node_id"`
	} `json:"connections"`
}

type Status

type Status struct {
	Name        string             `json:"name"`
	Role        string             `json:"role"`
	Devices     []StatusDevice     `json:"devices"`
	Connections []StatusConnection `json:"connections"`
}

Status is the state of a resource as drbdsetup status reports it, the part a start reads: the disk of each local volume, and for each peer the connection and how far behind its resync is.

func ParseStatus

func ParseStatus(b []byte) (Status, error)

ParseStatus reads the output of drbdsetup status --json --statistics for a resource.

func (Status) DiskStates

func (t Status) DiskStates() string

DiskStates returns the disk states of the local volumes, joined.

func (Status) HasConnected

func (t Status) HasConnected() bool

HasConnected says whether a peer is connected, which a resync needs.

func (Status) HasUpToDatePeer

func (t Status) HasUpToDatePeer() bool

HasUpToDatePeer says whether a connected peer holds the latest data, the source a resync of the local disk needs.

func (Status) IsUpToDate

func (t Status) IsUpToDate() bool

IsUpToDate says whether every local volume holds the latest data, which a promotion needs.

func (Status) OutOfSync

func (t Status) OutOfSync() uint64

OutOfSync returns the data, in KiB, still to resync from the peers, the largest a peer reports for each volume.

func (Status) Peers

func (t Status) Peers() string

Peers says, for each peer, its connection, its replication and its disk: "n2 Connected SyncTarget UpToDate".

type StatusConnPeerDevice

type StatusConnPeerDevice struct {
	Volume           int     `json:"volume"`
	ReplicationState string  `json:"replication-state"`
	PeerDiskState    string  `json:"peer-disk-state"`
	OutOfSync        uint64  `json:"out-of-sync"`
	PercentInSync    float64 `json:"percent-in-sync"`
}

type StatusConnection

type StatusConnection struct {
	PeerNodeID      int                    `json:"peer-node-id"`
	Name            string                 `json:"name"`
	ConnectionState string                 `json:"connection-state"`
	PeerDevices     []StatusConnPeerDevice `json:"peer_devices"`
}

type StatusDevice

type StatusDevice struct {
	Volume    int    `json:"volume"`
	DiskState string `json:"disk-state"`
}

type T

type T struct {
	// contains filtered or unexported fields
}

func New

func New(res string, opts ...funcopt.O) *T

func (*T) Adjust

func (t *T) Adjust(ctx context.Context) error

func (*T) Attach

func (t *T) Attach(ctx context.Context) error

func (*T) ConfigurePeerMultiPrimary

func (t *T) ConfigurePeerMultiPrimary(ctx context.Context, peer string, enabled bool) error

ConfigurePeerMultiPrimary sets the allow-two-primaries net-option on the specified resource connection (res:peer).

func (*T) ConnState

func (t *T) ConnState(ctx context.Context, nodeID string) (string, error)

func (*T) ConnStates

func (t *T) ConnStates(ctx context.Context) (CStateM, error)

func (*T) Connect

func (t *T) Connect(ctx context.Context, nodeID string) error

func (*T) ConnectAndWaitConnectingOrConnected

func (t *T) ConnectAndWaitConnectingOrConnected(ctx context.Context, nodeID string) (string, error)

func (*T) Create

func (t *T) Create(disk string, addr string, port int) error

func (*T) CreateMD

func (t *T) CreateMD(ctx context.Context, maxPeers int) error

func (*T) DetachForce

func (t *T) DetachForce(ctx context.Context) error

func (*T) Disconnect

func (t *T) Disconnect(ctx context.Context) error

func (*T) DiskStates

func (t *T) DiskStates(ctx context.Context) ([]string, error)

func (*T) Down

func (t *T) Down(ctx context.Context) error

func (*T) HasMD

func (t *T) HasMD(ctx context.Context) (bool, error)

func (*T) IsDefined

func (t *T) IsDefined(ctx context.Context) (bool, error)

func (*T) IsUp

func (t *T) IsUp() (bool, string, error)

func (*T) ModProbe

func (t *T) ModProbe(ctx context.Context) error

func (*T) Primary

func (t *T) Primary(ctx context.Context) error

func (*T) PrimaryForce

func (t *T) PrimaryForce(ctx context.Context) error

func (*T) Remove

func (t *T) Remove() error

func (*T) Resize

func (t *T) Resize(ctx context.Context) error

Resize makes the drbd resource use the current size of the device behind it, on every node holding a replica.

The backing device has to have been grown on every node first: drbd can only offer what the smallest replica holds.

func (*T) Role

func (t *T) Role(ctx context.Context) (string, error)

func (*T) Secondary

func (t *T) Secondary(ctx context.Context) error

func (*T) Show

func (t *T) Show(ctx context.Context) (DrbdShow, error)

func (*T) StartConnection

func (t *T) StartConnection(ctx context.Context, nodeID string) error

startConnection establishes a connection for the DRBD resource, managing its state transitions as needed. It returns an error if the connection process fails.

func (*T) StartConnections

func (t *T) StartConnections(ctx context.Context, peers ...string) error

startConnections establishes a connection for the DRBD resource, managing its state transitions as needed. It returns an error if the connection process fails.

func (*T) Status

func (t *T) Status(ctx context.Context) (Status, error)

Status returns the state of the resource, its disks, its connections and their resync.

func (*T) TryStartConnection

func (t *T) TryStartConnection(ctx context.Context, nodeID string) error

func (*T) Up

func (t *T) Up(ctx context.Context) error

func (*T) WaitCState

func (t *T) WaitCState(ctx context.Context, nodeID string, timeout time.Duration, candidates ...string) (string, error)

func (*T) WaitConnectingOrConnected

func (t *T) WaitConnectingOrConnected(ctx context.Context, nodeID string) (string, error)

func (*T) WaitIsDefined

func (t *T) WaitIsDefined(ctx context.Context, timeout time.Duration, target bool) error

func (*T) WipeMD

func (t *T) WipeMD(ctx context.Context) error

WipeMD executes the `wipe-md` drbd command.

Ignore the exit code `20`:

Returned when the sub dev is not found.
No need to fail, as the sub dev is surely flagged for unprovision too,
which will wipe metadata.
This situation happens on unprovision on a stopped instance, when drbd
is stacked over another (stopped) disk resource.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL