storage

package
v0.0.0-...-d3dc1b7 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: AGPL-3.0 Imports: 61 Imported by: 0

Documentation

Index

Constants

View Source
const PoolIDTemporary = -1

PoolIDTemporary is used to indicate a temporary pool instance that is not in the database.

Variables

View Source
var ErrBackupSnapshotsMismatch = errors.New("Backup snapshots mismatch")

ErrBackupSnapshotsMismatch is the "Backup snapshots mismatch" error.

View Source
var ErrNilValue = errors.New("Nil value provided")

ErrNilValue is the "Nil value provided" error.

Functions

func BucketDBCreate

func BucketDBCreate(ctx context.Context, pool Pool, projectName string, bucket *api.StorageBucketsPost) (int64, error)

BucketDBCreate creates a bucket in the database. The supplied bucket's config may be modified with defaults for the storage pool being used. Returns bucket DB record ID.

func BucketDBDelete

func BucketDBDelete(ctx context.Context, pool Pool, bucketID int64) error

BucketDBDelete deletes a bucket from the database.

func CompareSnapshots

func CompareSnapshots(sourceSnapshots []ComparableSnapshot, targetSnapshots []ComparableSnapshot) (syncSourceSnapshots []int, deleteTargetSnapshots []int)

CompareSnapshots returns a list of snapshot indexes (from the associated input slices) to sync from the source and to delete from the target respectively. A snapshot will be added to "to sync from source" slice if it either doesn't exist in the target or its ID or creation date is different to the source. A snapshot will be added to the "to delete from target" slice if it doesn't exist in the source or its ID or creation date is different to the source.

func ConfigDiff

func ConfigDiff(oldConfig map[string]string, newConfig map[string]string) ([]string, bool)

ConfigDiff returns a diff of the provided configs. Additionally, it returns whether or not only user properties have been changed.

func CreateContainerMountpoint

func CreateContainerMountpoint(mountPoint string, mountPointSymlink string, privileged bool) error

CreateContainerMountpoint creates the provided container mountpoint and symlink.

func CreateSnapshotMountpoint

func CreateSnapshotMountpoint(snapshotMountpoint string, snapshotsSymlinkTarget string, snapshotsSymlink string) error

CreateSnapshotMountpoint creates the provided container snapshot mountpoint and symlink.

func FallbackMigrationType

func FallbackMigrationType(contentType drivers.ContentType) migration.MigrationFSType

FallbackMigrationType returns the fallback migration transport to use based on volume content type.

func ImageUnpack

func ImageUnpack(s *state.State, projectName string, imageFile string, vol drivers.Volume, destBlockFile string, allowUnsafeResize bool, progressHandler ioprogress.ProgressHandler) (int64, error)

ImageUnpack unpacks a filesystem image into the destination path. There are several formats that images can come in: Container Format A: Separate metadata tarball and root squashfs file.

  • Unpack metadata tarball into mountPath.
  • Unpack root squashfs file into mountPath/rootfs.

Container Format B: Combined tarball containing metadata files and root squashfs.

  • Unpack combined tarball into mountPath.

VM Format A: Separate metadata tarball and root qcow2 file.

  • Unpack metadata tarball into mountPath.
  • Check rootBlockPath is a file and convert qcow2 file into raw format in rootBlockPath.

func InstanceContentType

func InstanceContentType(inst instance.Instance) drivers.ContentType

InstanceContentType returns the instance's content type.

func InstanceDiskBlockSize

func InstanceDiskBlockSize(pool Pool, inst instance.Instance, progressReporter ioprogress.ProgressReporter) (int64, error)

InstanceDiskBlockSize returns the block device size for the instance's disk. This will mount the instance if not already mounted and will unmount at the end if needed.

func InstancePath

func InstancePath(instanceType instancetype.Type, projectName, instanceName string, isSnapshot bool) string

InstancePath returns the directory of an instance or snapshot.

func InstanceTypeToVolumeType

func InstanceTypeToVolumeType(instType instancetype.Type) (drivers.VolumeType, error)

InstanceTypeToVolumeType converts instance type to storage driver volume type.

func InstanceUnmount

func InstanceUnmount(pool Pool, inst instance.Instance, progressReporter ioprogress.ProgressReporter) error

InstanceUnmount unmounts an instance's storage volume (if not in use).

func IsAvailable

func IsAvailable(poolName string) bool

IsAvailable checks if a pool is available.

func NewStorageCache

func NewStorageCache(p Pool) *storageCache

NewStorageCache returns a new instance of the storage cache for the provided pool. Returns nil if the provided pool is not of type [*lxdBackend].

func Patch

func Patch(s *state.State, patchName string) error

Patch applies specified patch to all storage pools. All storage pools must be available locally before any storage pools are patched.

func RenderSnapshotUsage

func RenderSnapshotUsage(s *state.State, snapInst instance.Instance) func(response any) error

RenderSnapshotUsage can be used as an optional argument to Instance.Render() to return snapshot usage. As this is a relatively expensive operation it is provided as an optional feature rather than on by default.

func UsedBy

func UsedBy(ctx context.Context, s *state.State, pool Pool, firstOnly bool, memberSpecific bool, ignoreVolumeType ...string) ([]string, error)

UsedBy returns list of API resources using storage pool. Accepts firstOnly argument to indicate that only the first resource using network should be returned. This can help to quickly check if the storage pool is in use. If memberSpecific is true, then the search is restricted to volumes that belong to this member or belong to all members. The ignoreVolumeType argument can be used to exclude certain volume type(s) from the list.

func VolumeContentTypeToDBContentType

func VolumeContentTypeToDBContentType(contentType drivers.ContentType) (cluster.StoragePoolVolumeContentType, error)

VolumeContentTypeToDBContentType converts volume type to internal code.

func VolumeDBContentTypeToContentType

func VolumeDBContentTypeToContentType(volDBType cluster.StoragePoolVolumeContentType) drivers.ContentType

VolumeDBContentTypeToContentType converts internal content type DB code to driver representation.

func VolumeDBCreate

func VolumeDBCreate(pool Pool, projectName string, volumeName string, volumeDescription string, volumeType drivers.VolumeType, snapshot bool, volumeConfig map[string]string, creationDate time.Time, expiryDate time.Time, contentType drivers.ContentType, removeUnknownKeys bool, hasSource bool) error

VolumeDBCreate creates a volume in the database. If volumeConfig is supplied, it is modified with any driver level default config options (if not set). If removeUnknownKeys is true, any unknown config keys are removed from volumeConfig rather than failing.

func VolumeDBDelete

func VolumeDBDelete(pool Pool, projectName string, volumeName string, volumeType drivers.VolumeType) error

VolumeDBDelete deletes a volume from the database.

func VolumeDBGet

func VolumeDBGet(pool Pool, projectName string, volumeName string, volumeType drivers.VolumeType) (*db.StorageVolume, error)

VolumeDBGet loads a volume from the database.

func VolumeDBSnapshotsGet

func VolumeDBSnapshotsGet(pool Pool, projectName string, volume string, volumeType drivers.VolumeType) ([]db.StorageVolumeArgs, error)

VolumeDBSnapshotsGet loads a list of snapshots volumes from the database.

func VolumeDBTypeToType

func VolumeDBTypeToType(volDBType cluster.StoragePoolVolumeType) drivers.VolumeType

VolumeDBTypeToType converts internal volume type DB code to storage driver volume type.

func VolumeDetermineNextSnapshotName

func VolumeDetermineNextSnapshotName(ctx context.Context, s *state.State, pool string, volumeName string, volumeConfig map[string]string) (string, error)

VolumeDetermineNextSnapshotName determines a name for next snapshot of a volume following the volume's snapshots.pattern or the provided default pattern.

func VolumeTypeToAPIInstanceType

func VolumeTypeToAPIInstanceType(volType drivers.VolumeType) (api.InstanceType, error)

VolumeTypeToAPIInstanceType converts storage driver volume type to API instance type type.

func VolumeTypeToDBType

func VolumeTypeToDBType(volType drivers.VolumeType) (cluster.StoragePoolVolumeType, error)

VolumeTypeToDBType converts volume type to internal volume type DB code.

func VolumeUsedByDaemon

func VolumeUsedByDaemon(s *state.State, poolName string, volumeName string) (bool, error)

VolumeUsedByDaemon indicates whether the volume is used by daemon storage.

func VolumeUsedByExclusiveRemoteInstancesWithProfiles

func VolumeUsedByExclusiveRemoteInstancesWithProfiles(s *state.State, poolName string, projectName string, vol *api.StorageVolume) (*db.InstanceArgs, error)

VolumeUsedByExclusiveRemoteInstancesWithProfiles checks if custom volume is exclusively attached to a remote instance. Returns the remote instance that has the volume exclusively attached. Returns nil if volume available.

func VolumeUsedByInstanceDevices

func VolumeUsedByInstanceDevices(s *state.State, poolName string, projectName string, vol *api.StorageVolume, expandDevices bool, instanceFunc func(inst db.InstanceArgs, project api.Project, usedByDevices []string) error) error

VolumeUsedByInstanceDevices finds instances using a volume (either directly or via their expanded profiles if expandDevices is true) and passes them to instanceFunc for evaluation. If instanceFunc returns an error then it is returned immediately. The instanceFunc is executed during a DB transaction, so DB queries are not permitted. The instanceFunc is provided with a instance config, project config, instance's profiles and a list of device names that are using the volume.

func VolumeUsedByProfileDevices

func VolumeUsedByProfileDevices(s *state.State, poolName string, projectName string, vol *api.StorageVolume, profileFunc func(profileID int64, profile api.Profile, project api.Project, usedByDevices []string) error) error

VolumeUsedByProfileDevices finds profiles using a volume and passes them to profileFunc for evaluation. The profileFunc is provided with a profile config, project config and a list of device names that are using the volume.

Types

type ComparableSnapshot

type ComparableSnapshot struct {
	// Name of the snapshot (without the parent name).
	Name string

	// Identifier of the snapshot (that remains the same when copied between pools).
	ID string

	// Creation date time of the snapshot.
	CreationDate time.Time
}

ComparableSnapshot is used when comparing snapshots on different pools to see whether they differ.

type MountInfo

type MountInfo struct {
	DevSource deviceConfig.DevSource               // The location of the block disk (if supported).
	PostHooks []func(inst instance.Instance) error // Hooks to be called following a mount.
}

MountInfo represents info about the result of a mount operation.

func InstanceMount

func InstanceMount(pool Pool, inst instance.Instance, progressReporter ioprogress.ProgressReporter) (*MountInfo, error)

InstanceMount mounts an instance's storage volume (if not already mounted). Please call InstanceUnmount when finished.

type Pool

type Pool interface {
	Type

	// Pool.
	ID() int64
	Name() string
	Driver() drivers.Driver
	Description() string
	Status() string
	LocalStatus() string
	ToAPI() api.StoragePool

	GetResources() (*api.ResourcesStoragePool, error)
	IsUsed() (bool, error)
	Delete(clientType request.ClientType, progressReporter ioprogress.ProgressReporter) error
	Update(clientType request.ClientType, newDesc string, newConfig map[string]string, progressReporter ioprogress.ProgressReporter) error

	Create(clientType request.ClientType, progressReporter ioprogress.ProgressReporter) error
	Mount() (bool, error)
	Unmount() (bool, error)

	ApplyPatch(name string) error

	GetVolume(volumeType drivers.VolumeType, contentType drivers.ContentType, name string, config map[string]string) drivers.Volume

	// Instances.
	CreateInstance(inst instance.Instance, progressReporter ioprogress.ProgressReporter) error
	CreateInstanceFromBackup(srcBackup backup.Info, srcData io.ReadSeeker, progressReporter ioprogress.ProgressReporter) (func(instance.Instance) error, revert.Hook, error)
	CreateInstanceFromCopy(ctx context.Context, inst instance.Instance, src instance.Instance, snapshots bool, allowInconsistent bool, progressReporter ioprogress.ProgressReporter) error
	CreateInstanceFromImage(ctx context.Context, inst instance.Instance, fingerprint string, progressReporter ioprogress.ProgressReporter) error
	CreateInstanceFromMigration(ctx context.Context, inst instance.Instance, conn io.ReadWriteCloser, args migration.VolumeTargetArgs, progressReporter ioprogress.ProgressReporter) error
	CreateInstanceFromConversion(inst instance.Instance, conn io.ReadWriteCloser, args migration.VolumeTargetArgs, progressReporter ioprogress.ProgressReporter) error
	RenameInstance(inst instance.Instance, newName string, progressReporter ioprogress.ProgressReporter) error
	DeleteInstance(inst instance.Instance, progressReporter ioprogress.ProgressReporter) error
	UpdateInstance(ctx context.Context, inst instance.Instance, newDesc string, newConfig map[string]string, progressReporter ioprogress.ProgressReporter) error
	UpdateInstanceBackupFile(inst instance.Instance, snapshots bool, volBackupConf *backupConfig.Config, version uint32, progressReporter ioprogress.ProgressReporter) error
	GenerateInstanceBackupConfig(inst instance.Instance, snapshots bool, volBackupConf *backupConfig.Config, progressReporter ioprogress.ProgressReporter) (*backupConfig.Config, error)
	GenerateInstanceCustomVolumeBackupConfig(inst instance.Instance, cache *storageCache, snapshots bool, progressReporter ioprogress.ProgressReporter) (*backupConfig.Config, error)
	CheckInstanceBackupFileSnapshots(backupConf *backupConfig.Config, projectName string, progressReporter ioprogress.ProgressReporter) ([]*api.InstanceSnapshot, error)
	ImportInstance(inst instance.Instance, poolVol *backupConfig.Config, progressReporter ioprogress.ProgressReporter) (revert.Hook, error)
	CleanupInstancePaths(inst instance.Instance, progressReporter ioprogress.ProgressReporter) error

	MigrateInstance(ctx context.Context, inst instance.Instance, conn io.ReadWriteCloser, args *migration.VolumeSourceArgs, progressReporter ioprogress.ProgressReporter) error
	RefreshInstance(ctx context.Context, inst instance.Instance, src instance.Instance, srcSnapshots []instance.Instance, allowInconsistent bool, progressReporter ioprogress.ProgressReporter) error
	BackupInstance(inst instance.Instance, tarWriter *instancewriter.InstanceTarWriter, optimized bool, snapshots bool, version uint32, progressReporter ioprogress.ProgressReporter) error

	GetInstanceUsage(inst instance.Instance) (*VolumeUsage, error)
	SetInstanceQuota(inst instance.Instance, size string, vmStateSize string, progressReporter ioprogress.ProgressReporter) error

	MountInstance(inst instance.Instance, progressReporter ioprogress.ProgressReporter) (*MountInfo, error)
	UnmountInstance(inst instance.Instance, progressReporter ioprogress.ProgressReporter) error

	// Instance snapshots.
	CreateInstanceSnapshot(inst instance.Instance, src instance.Instance, progressReporter ioprogress.ProgressReporter) error
	RenameInstanceSnapshot(inst instance.Instance, newName string, progressReporter ioprogress.ProgressReporter) error
	DeleteInstanceSnapshot(inst instance.Instance, progressReporter ioprogress.ProgressReporter) error
	RestoreInstanceSnapshot(ctx context.Context, inst instance.Instance, src instance.Instance, progressReporter ioprogress.ProgressReporter) error
	MountInstanceSnapshot(inst instance.Instance, progressReporter ioprogress.ProgressReporter) (*MountInfo, error)
	UnmountInstanceSnapshot(inst instance.Instance, progressReporter ioprogress.ProgressReporter) error
	UpdateInstanceSnapshot(ctx context.Context, inst instance.Instance, newDesc string, newConfig map[string]string, progressReporter ioprogress.ProgressReporter) error

	// Images.
	EnsureImage(ctx context.Context, fingerprint string, projectName string, progressReporter ioprogress.ProgressReporter) error
	DeleteImage(ctx context.Context, fingerprint string, progressReporter ioprogress.ProgressReporter) error
	UpdateImage(ctx context.Context, fingerprint string, newDesc string, newConfig map[string]string, progressReporter ioprogress.ProgressReporter) error

	// Buckets.
	CreateBucket(projectName string, bucket api.StorageBucketsPost) error
	UpdateBucket(projectName string, bucketName string, bucket api.StorageBucketPut) error
	DeleteBucket(projectName string, bucketName string) error
	CreateBucketKey(projectName string, bucketName string, key api.StorageBucketKeysPost) (*api.StorageBucketKey, error)
	UpdateBucketKey(projectName string, bucketName string, keyName string, key api.StorageBucketKeyPut) error
	DeleteBucketKey(projectName string, bucketName string, keyName string) error
	GetBucketURL(bucketName string) *url.URL

	// Custom volumes.
	CreateCustomVolume(ctx context.Context, projectName string, volName string, desc string, config map[string]string, contentType drivers.ContentType, progressReporter ioprogress.ProgressReporter) error
	CreateCustomVolumeFromCopy(ctx context.Context, projectName, srcProjectName, volName, desc string, config map[string]string, srcPoolName, srcVolName string, snapshots bool, progressReporter ioprogress.ProgressReporter) error
	UpdateCustomVolume(ctx context.Context, projectName string, volName string, newDesc string, newConfig map[string]string, progressReporter ioprogress.ProgressReporter) error
	RenameCustomVolume(ctx context.Context, projectName string, volName string, newVolName string, progressReporter ioprogress.ProgressReporter) error
	DeleteCustomVolume(ctx context.Context, projectName string, volName string, progressReporter ioprogress.ProgressReporter) error
	GetCustomVolumeUsage(projectName string, volName string) (*VolumeUsage, error)
	MountCustomVolume(projectName string, volName string, progressReporter ioprogress.ProgressReporter) (*MountInfo, error)
	UnmountCustomVolume(projectName string, volName string, progressReporter ioprogress.ProgressReporter) (bool, error)
	ImportCustomVolume(projectName string, poolVol *backupConfig.Config, progressReporter ioprogress.ProgressReporter) (revert.Hook, error)
	RefreshCustomVolume(ctx context.Context, projectName, srcProjectName, volName, desc string, config map[string]string, srcPoolName, srcVolName string, snapshots bool, progressReporter ioprogress.ProgressReporter) error
	UpdateCustomVolumeBackupFiles(projectName string, volName string, snapshots bool, instances []instance.Instance, progressReporter ioprogress.ProgressReporter) error
	GenerateCustomVolumeBackupConfig(projectName string, volName string, snapshots bool, progressReporter ioprogress.ProgressReporter) (*backupConfig.Config, error)
	CreateCustomVolumeFromISO(ctx context.Context, projectName string, volName string, srcData io.ReadSeeker, size int64, progressReporter ioprogress.ProgressReporter) error
	CreateCustomVolumeFromTarball(ctx context.Context, projectName string, volName string, srcData *os.File, progressReporter ioprogress.ProgressReporter) error

	// Custom volume snapshots.
	CreateCustomVolumeSnapshot(ctx context.Context, projectName string, volName string, newSnapshotName string, newDescription string, newExpiryDate *time.Time, progressReporter ioprogress.ProgressReporter) (*uuid.UUID, error)
	RenameCustomVolumeSnapshot(ctx context.Context, projectName string, volName string, newSnapshotName string, progressReporter ioprogress.ProgressReporter) error
	DeleteCustomVolumeSnapshot(ctx context.Context, projectName string, volName string, progressReporter ioprogress.ProgressReporter) error
	UpdateCustomVolumeSnapshot(ctx context.Context, projectName string, volName string, newDesc string, newConfig map[string]string, newExpiryDate time.Time, progressReporter ioprogress.ProgressReporter) error
	RestoreCustomVolume(ctx context.Context, projectName string, volName string, snapshotName string, progressReporter ioprogress.ProgressReporter) error

	// Custom volume migration.
	MigrationTypes(contentType drivers.ContentType, refresh bool, copySnapshots bool) []migration.Type
	CreateCustomVolumeFromMigration(ctx context.Context, projectName string, conn io.ReadWriteCloser, args migration.VolumeTargetArgs, progressReporter ioprogress.ProgressReporter) error
	MigrateCustomVolume(projectName string, conn io.ReadWriteCloser, args *migration.VolumeSourceArgs, progressReporter ioprogress.ProgressReporter) error

	// Custom volume backups.
	BackupCustomVolume(projectName string, volName string, tarWriter *instancewriter.InstanceTarWriter, optimized bool, snapshots bool, progressReporter ioprogress.ProgressReporter) error
	CreateCustomVolumeFromBackup(ctx context.Context, srcBackup backup.Info, srcData io.ReadSeeker, progressReporter ioprogress.ProgressReporter) error

	// Storage volume recovery.
	ListUnknownVolumes(progressReporter ioprogress.ProgressReporter) (map[string][]*backupConfig.Config, error)
}

Pool represents a LXD storage pool.

func LoadByInstance

func LoadByInstance(s *state.State, inst instance.Instance) (Pool, error)

LoadByInstance retrieves the pool from the database using the instance's pool. If the pool's driver is not recognised then drivers.ErrUnknownDriver is returned. If the pool's driver does not support the instance's type then drivers.ErrNotSupported is returned.

func LoadByName

func LoadByName(s *state.State, name string) (Pool, error)

LoadByName retrieves the pool from the database by its name and returns a Pool interface. If the pool's driver is not recognised then drivers.ErrUnknownDriver is returned.

func LoadByRecord

func LoadByRecord(s *state.State, poolID int64, poolInfo api.StoragePool, poolMembers map[int64]db.StoragePoolNode) (Pool, error)

LoadByRecord instantiates a pool from its record and returns a Pool interface. If the pool's driver is not recognised then drivers.ErrUnknownDriver is returned.

func NewTemporary

func NewTemporary(state *state.State, info *api.StoragePool) (Pool, error)

NewTemporary instantiates a temporary pool from config supplied and returns a Pool interface. Not all functionality will be available due to the lack of Pool ID. If the pool's driver is not recognised then drivers.ErrUnknownDriver is returned.

type Type

type Type interface {
	ValidateName(name string) error
	Validate(config map[string]string) error
}

Type represents a LXD storage pool type.

func LoadByType

func LoadByType(state *state.State, driverType string) (Type, error)

LoadByType loads a network by driver type.

type VolumeUsage

type VolumeUsage struct {
	Used  int64
	Total int64
}

VolumeUsage contains the used and total size of a volume.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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