drbd

package
v3.0.0-beta13 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

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"
)

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 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) 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) 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) 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