ceph

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: AGPL-3.0 Imports: 19 Imported by: 0 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

Overview

Package ceph is VirtoMir's hyper-converged Ceph (D4, ADR-0073): bootstrapping a cluster with cephadm on the VirtoMir hosts, adding hosts and OSDs (only on empty disks), health and capacity telemetry, RBD pools that become libvirt pools on every member, storage policies that name a pool for new disks, and noout around host maintenance. It drives the stock tools (cephadm, ceph, rbd, lsblk) through a Runner, so every command it would run is tested without Ceph installed. Experimental: not tested on hardware.

Index

Constants

View Source
const ClientUser = "virtomir"

ClientUser is the cephx user VirtoMir creates for libvirt: RBD rights only, not admin.

Variables

View Source
var (
	ErrInvalid      = errors.New("invalid")
	ErrNotFound     = errors.New("not found")
	ErrExists       = errors.New("exists")
	ErrBusy         = errors.New("in use")
	ErrDiskNotEmpty = errors.New("disk not empty")
)

Errors for the API.

View Source
var AuthorizedKeysFile = "/root/.ssh/authorized_keys"

AuthorizedKeysFile is where the cluster's SSH key goes so cephadm can manage this host.

View Source
var Busy = func(path string) bool {
	f, err := os.OpenFile(path, os.O_RDONLY|os.O_EXCL, 0)
	if err != nil {
		return errors.Is(err, syscall.EBUSY)
	}
	_ = f.Close()
	return false
}

Busy reports whether the kernel holds a disk exclusively, which catches what leaves no signature on it (an iSCSI target's backing disk, a device-mapper user). Tests replace it.

Functions

func AddHost

func AddHost(ctx context.Context, r Runner, hostname, ip string) error

AddHost has the orchestrator take over a host; its root must already trust the cluster's SSH key (AuthorizePeerKey there).

func AddOSD

func AddOSD(ctx context.Context, r Runner, hostname string, disk DiskInfo) error

AddOSD makes an OSD of a disk on a host. disk is what that host reported about it (the API asks the host itself); a disk that is not empty is refused here, and ceph-volume refuses it again.

func AuthorizePeerKey

func AuthorizePeerKey(pubKey string) error

AuthorizePeerKey lets the cluster's cephadm log in here as root, once.

func CreateRBDPool

func CreateRBDPool(ctx context.Context, r Runner, spec PoolSpec) error

CreateRBDPool creates a pool for RBD images.

func DeleteRBDPool

func DeleteRBDPool(ctx context.Context, r Runner, name string, dataPool string) error

DeleteRBDPool removes a pool (and its data pool), with all images in it. Ceph only deletes pools while mon_allow_pool_delete is on, so it is switched on just for this.

func EnsureDiskEmpty

func EnsureDiskEmpty(ctx context.Context, r Runner, path string) error

EnsureDiskEmpty refuses a disk that holds anything.

func EnterHostMaintenance

func EnterHostMaintenance(ctx context.Context, r Runner, store *Store, hostname string) error

EnterHostMaintenance sets noout and stops the host's Ceph daemons. Ceph refuses when stopping them would make data unavailable; its answer is the error.

func ExitHostMaintenance

func ExitHostMaintenance(ctx context.Context, r Runner, store *Store, hostname string) error

ExitHostMaintenance starts the host's daemons again; the last host to leave maintenance clears noout.

func LibvirtPool

func LibvirtPool(cfg ClusterConfig, cephPool, libvirtName string) virt.PoolSpec

LibvirtPool is the libvirt pool spec for an RBD pool of the cluster.

func MarkUsed

func MarkUsed(disks []DiskInfo, used func(path string) string)

MarkUsed refuses the disks that are something else's (a libvirt pool's volume, a machine's disk); used says by what ("" = nothing).

func SetCompression

func SetCompression(ctx context.Context, r Runner, pool, dataPool, mode, algorithm string) error

SetCompression sets BlueStore compression on the pool that holds a pool's data (the data pool of an erasure-coded one); it applies to data written from now on.

func SetNoout

func SetNoout(ctx context.Context, r Runner, store *Store, on bool) error

SetNoout sets or clears the cluster's noout flag: with it, OSDs that go down are not marked out, so a host that is serviced for a while does not start a rebalance.

Types

type BootstrapSpec

type BootstrapSpec struct {
	MonIP              string `json:"monIp"`
	ClusterNetwork     string `json:"clusterNetwork,omitempty"`
	InitialOSDDisk     string `json:"initialOsdDisk,omitempty"`
	SingleHostDefaults bool   `json:"singleHostDefaults"`
}

BootstrapSpec is what bootstrapping a cluster on this host needs.

func (BootstrapSpec) Validate

func (b BootstrapSpec) Validate() error

Validate checks the addresses and the disk path.

type CapacityReport

type CapacityReport struct {
	TotalBytes  uint64         `json:"totalBytes"`
	UsedBytes   uint64         `json:"usedBytes"`
	AvailBytes  uint64         `json:"availBytes"`
	PercentUsed float64        `json:"percentUsed"`
	Pools       []PoolCapacity `json:"pools"`
}

CapacityReport is the raw capacity and what each pool stores.

func Capacity

func Capacity(ctx context.Context, r Runner) (CapacityReport, error)

Capacity reads ceph df detail.

type CephHost

type CephHost struct {
	Hostname string   `json:"hostname"`
	IP       string   `json:"ip"`
	Labels   []string `json:"labels"`
	Status   string   `json:"status"` // online, offline or maintenance
}

CephHost is a host of the Ceph cluster as the orchestrator sees it.

func Hosts

func Hosts(ctx context.Context, r Runner) ([]CephHost, error)

Hosts lists the orchestrator's hosts.

type ClusterConfig

type ClusterConfig struct {
	FSID          string   `json:"fsid"`
	BootstrapHost string   `json:"bootstrapHost"`
	MonEndpoints  []string `json:"monEndpoints"`
	ClientUser    string   `json:"clientUser"`
	// ClientKey is the cephx key libvirt pools use; the API never shows it.
	ClientKey        string    `json:"clientKey,omitempty"`
	SSHPublicKey     string    `json:"sshPublicKey"`
	MaintenanceHosts []string  `json:"maintenanceHosts"`
	Noout            bool      `json:"noout"`
	Created          time.Time `json:"created"`
	Updated          time.Time `json:"updated"`
}

ClusterConfig is what VirtoMir knows of the Ceph cluster it bootstrapped or joined.

func AdoptCluster

func AdoptCluster(ctx context.Context, r Runner, store *Store, hostname string) (ClusterConfig, error)

AdoptCluster records an existing cluster this host can reach as admin (for clusters made outside VirtoMir).

func Bootstrap

func Bootstrap(ctx context.Context, r Runner, store *Store, hostname string, spec BootstrapSpec) (ClusterConfig, error)

Bootstrap creates a Ceph cluster with this host (hostname) as its first monitor and manager, creates VirtoMir's RBD user and, with InitialOSDDisk, the first OSD. The disk is checked before cephadm runs: a disk with data stops everything.

type ClusterHealth

type ClusterHealth struct {
	Status string        `json:"status"` // HEALTH_OK, HEALTH_WARN or HEALTH_ERR
	Checks []HealthCheck `json:"checks"`
}

ClusterHealth is Ceph's overall verdict and its checks.

func Health

func Health(ctx context.Context, r Runner) (ClusterHealth, error)

Health asks Ceph how it is, with the details of each check.

func (ClusterHealth) Summary

func (h ClusterHealth) Summary() string

Summary is the checks' summaries in one line.

type Daemons

type Daemons struct {
	Mons       int      `json:"mons"`
	Quorum     []string `json:"quorum"`
	MgrUp      bool     `json:"mgrUp"`
	OSDs       int      `json:"osds"`
	OSDsUp     int      `json:"osdsUp"`
	OSDsIn     int      `json:"osdsIn"`
	NooutIsSet bool     `json:"noout"`
}

Daemons counts monitors, managers and OSDs.

type DiskInfo

type DiskInfo struct {
	Path       string   `json:"path"`
	Name       string   `json:"name"`
	SizeBytes  uint64   `json:"sizeBytes"`
	Rotational bool     `json:"rotational"`
	DeviceType string   `json:"deviceType"` // ssd, nvme or hdd
	MountPoint string   `json:"mountPoint,omitempty"`
	FSType     string   `json:"fsType,omitempty"`
	Partitions []string `json:"partitions,omitempty"`
	// Empty: no partition table, partitions, file system, LVM/ZFS/RAID label or mount.
	// Only empty disks become OSDs; RefusalReason says what is on the others.
	Empty         bool   `json:"empty"`
	RefusalReason string `json:"refusalReason,omitempty"`
}

DiskInfo is a host disk and whether Ceph may take it.

func InspectDisk

func InspectDisk(ctx context.Context, r Runner, path string) (DiskInfo, error)

InspectDisk describes one disk.

func ListDisks

func ListDisks(ctx context.Context, r Runner) ([]DiskInfo, error)

ListDisks lists this host's whole disks (no loop, RAM, RBD or NBD devices).

type Exec

type Exec struct{}

Exec runs commands on this host.

func (Exec) Run

func (Exec) Run(ctx context.Context, name string, args ...string) ([]byte, error)

Run runs name with args; an error carries the command's standard error.

type HealthCheck

type HealthCheck struct {
	Name     string   `json:"name"`
	Severity string   `json:"severity"` // HEALTH_WARN or HEALTH_ERR
	Summary  string   `json:"summary"`
	Detail   []string `json:"detail,omitempty"`
}

HealthCheck is one problem Ceph reports.

type OSDNode

type OSDNode struct {
	ID          int     `json:"id"`
	Name        string  `json:"name"`
	Type        string  `json:"type"`             // root, host, osd, …
	Status      string  `json:"status,omitempty"` // up or down (OSDs)
	In          bool    `json:"in"`
	Weight      float64 `json:"weight"`
	DeviceClass string  `json:"deviceClass,omitempty"`
	Children    []int   `json:"children,omitempty"`
}

OSDNode is a node of the CRUSH tree: the root, hosts and OSDs.

func OSDTree

func OSDTree(ctx context.Context, r Runner) ([]OSDNode, error)

OSDTree reads the CRUSH tree.

type PGSummary

type PGSummary struct {
	Total  int            `json:"total"`
	States map[string]int `json:"states"`
}

PGSummary counts the placement groups by state.

type PoliciesShared

type PoliciesShared struct {
	Version  int             `json:"version"`
	Policies []StoragePolicy `json:"policies"`
}

PoliciesShared is the versioned policy list members exchange (newest version wins).

type PoolCapacity

type PoolCapacity struct {
	ID          int     `json:"id"`
	Name        string  `json:"name"`
	StoredBytes uint64  `json:"storedBytes"`
	Objects     uint64  `json:"objects"`
	PercentUsed float64 `json:"percentUsed"`
	MaxAvail    uint64  `json:"maxAvailBytes"`
	// Compressed is the raw space compressed data takes, CompressedFrom what it was before
	// (BlueStore compression, ADR-0074).
	Compressed     uint64 `json:"compressedBytes"`
	CompressedFrom uint64 `json:"compressedFromBytes"`
}

PoolCapacity is one pool's share of the cluster.

type PoolDetail

type PoolDetail struct {
	ID          int     `json:"id"`
	Name        string  `json:"name"`
	Type        string  `json:"type"` // replicated or erasure
	Size        int     `json:"size"` // copies (replicated) or k+m (erasure)
	MinSize     int     `json:"minSize"`
	ECProfile   string  `json:"ecProfile,omitempty"`
	DataPool    string  `json:"dataPool,omitempty"` // erasure: where the data goes
	StoredBytes uint64  `json:"storedBytes"`
	PercentUsed float64 `json:"percentUsed"`
	MaxAvail    uint64  `json:"maxAvailBytes"`
	// Compression of the pool that holds the data (none, passive, aggressive, force) and
	// what it saves: CompressedFrom bytes were stored as Compressed.
	CompressionMode      string `json:"compressionMode"`
	CompressionAlgorithm string `json:"compressionAlgorithm,omitempty"`
	Compressed           uint64 `json:"compressedBytes"`
	CompressedFrom       uint64 `json:"compressedFromBytes"`
}

PoolDetail is an RBD pool and what it stores.

func ListRBDPools

func ListRBDPools(ctx context.Context, r Runner) ([]PoolDetail, error)

ListRBDPools lists the pools with the rbd application; an erasure-coded pool shows as its metadata pool with the data pool's usage.

type PoolSpec

type PoolSpec struct {
	Name        string `json:"name"`
	Type        string `json:"type"`                  // replicated or erasure
	ReplicaSize int    `json:"replicaSize,omitempty"` // replicated: copies, default 3
	ECK         int    `json:"ecK,omitempty"`         // erasure: data chunks, default 4
	ECM         int    `json:"ecM,omitempty"`         // erasure: coding chunks, default 2
	DeviceClass string `json:"deviceClass,omitempty"` // ssd, hdd or nvme: only OSDs of that class
	PGNum       int    `json:"pgNum,omitempty"`       // first placement group count; the autoscaler adjusts it
}

PoolSpec is an RBD pool to create. Erasure-coded pools keep their data in <name>-data and the image metadata in <name> (RBD needs a replicated pool for that); libvirt only ever sees <name>.

func (*PoolSpec) Normalize

func (p *PoolSpec) Normalize() error

Normalize fills the defaults and checks the rest.

type Runner

type Runner interface {
	Run(ctx context.Context, name string, args ...string) ([]byte, error)
}

Runner runs a command and returns its standard output.

type StoragePolicy

type StoragePolicy struct {
	ID          string    `json:"id"`
	Name        string    `json:"name"`
	Description string    `json:"description,omitempty"`
	Pool        string    `json:"pool"`
	Default     bool      `json:"default"`
	Created     time.Time `json:"created"`
	Updated     time.Time `json:"updated"`
}

StoragePolicy names the libvirt pool new disks of that kind go to ("fast", "replica-3", "cold-ec"), so people pick an intent instead of a pool. Pools are often Ceph RBD pools, but any pool works.

type Store

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

Store keeps -state-dir/ceph.json: the cluster this host manages and the storage policies, which are the same on every member.

func Open

func Open(path string) (*Store, error)

Open loads path; a missing file is an empty store.

func (*Store) Adopt

func (s *Store) Adopt(sh PoliciesShared) (bool, error)

Adopt takes over a member's policies when they are newer; it reports whether it did.

func (*Store) Config

func (s *Store) Config() (ClusterConfig, bool)

Config returns the cluster configuration, if this host has one.

func (*Store) CreatePolicy

func (s *Store) CreatePolicy(p StoragePolicy) (StoragePolicy, error)

CreatePolicy adds a policy.

func (*Store) DeletePolicy

func (s *Store) DeletePolicy(id string) error

DeletePolicy removes a policy; machines keep their disks where they are.

func (*Store) Policies

func (s *Store) Policies() []StoragePolicy

Policies lists the storage policies by name.

func (*Store) Policy

func (s *Store) Policy(id string) (StoragePolicy, bool)

Policy returns one policy.

func (*Store) SaveConfig

func (s *Store) SaveConfig(c ClusterConfig) error

SaveConfig keeps c.

func (*Store) SetHostMaintenance

func (s *Store) SetHostMaintenance(host string, on bool) error

SetHostMaintenance records a host entering or leaving maintenance.

func (*Store) SetNoout

func (s *Store) SetNoout(noout bool) error

SetNoout records whether the cluster's noout flag is set.

func (*Store) Shared

func (s *Store) Shared() PoliciesShared

Shared returns the policies with their version.

func (*Store) UpdatePolicy

func (s *Store) UpdatePolicy(p StoragePolicy) (StoragePolicy, error)

UpdatePolicy changes a policy's name, description, pool and default flag.

type Telemetry

type Telemetry struct {
	FSID      string         `json:"fsid"`
	Health    ClusterHealth  `json:"health"`
	Daemons   Daemons        `json:"daemons"`
	Capacity  CapacityReport `json:"capacity"`
	OSDTree   []OSDNode      `json:"osdTree"`
	PGs       PGSummary      `json:"pgs"`
	Collected time.Time      `json:"collected"`
}

Telemetry is the cluster at one moment.

func Collect

func Collect(ctx context.Context, r Runner, now time.Time) (Telemetry, error)

Collect reads status, health detail, df and the OSD tree.

Jump to

Keyboard shortcuts

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