storage

package
v0.0.0-...-00587b8 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2020 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBackupSnapshotsMismatch = fmt.Errorf("Backup snapshots mismatch")

ErrBackupSnapshotsMismatch is the "Backup snapshots mismatch" error.

View Source
var ErrNilValue = fmt.Errorf("Nil value provided")

ErrNilValue is the "Nil value provided" error

View Source
var ErrNotImplemented = fmt.Errorf("Not implemented")

ErrNotImplemented is the "Not implemented" error

View Source
var ErrRunningQuotaResizeNotSupported = fmt.Errorf("Running quota resize not supported")

ErrRunningQuotaResizeNotSupported is the "Running quota resize not supported" error.

View Source
var StorageVolumeConfigKeys = map[string]func(value string) ([]string, error){
	"block.filesystem": func(value string) ([]string, error) {
		err := validate.IsOneOf(value, []string{"btrfs", "ext4", "xfs"})
		if err != nil {
			return nil, err
		}

		return []string{"ceph", "lvm"}, nil
	},
	"block.mount_options": func(value string) ([]string, error) {
		return []string{"ceph", "lvm"}, validate.IsAny(value)
	},
	"security.shifted": func(value string) ([]string, error) {
		return SupportedPoolTypes, validate.Optional(validate.IsBool)(value)
	},
	"security.unmapped": func(value string) ([]string, error) {
		return SupportedPoolTypes, validate.Optional(validate.IsBool)(value)
	},
	"size": func(value string) ([]string, error) {
		if value == "" {
			return SupportedPoolTypes, nil
		}

		_, err := units.ParseByteSizeString(value)
		if err != nil {
			return nil, err
		}

		return SupportedPoolTypes, nil
	},
	"volatile.idmap.last": func(value string) ([]string, error) {
		return SupportedPoolTypes, validate.IsAny(value)
	},
	"volatile.idmap.next": func(value string) ([]string, error) {
		return SupportedPoolTypes, validate.IsAny(value)
	},
	"zfs.remove_snapshots": func(value string) ([]string, error) {
		err := validate.Optional(validate.IsBool)(value)
		if err != nil {
			return nil, err
		}

		return []string{"zfs"}, nil
	},
	"zfs.use_refquota": func(value string) ([]string, error) {
		err := validate.Optional(validate.IsBool)(value)
		if err != nil {
			return nil, err
		}

		return []string{"zfs"}, nil
	},
}

StorageVolumeConfigKeys config validation for btrfs, ceph, cephfs, dir, lvm, zfs types. Deprecated: these are being moved to the per-storage-driver implementations.

View Source
var SupportedPoolTypes = []string{"btrfs", "ceph", "cephfs", "dir", "lvm", "zfs"}

SupportedPoolTypes the types of pools supported. Deprecated: this is being replaced with drivers.SupportedDrivers()

Functions

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 GetContainerMountPoint

func GetContainerMountPoint(projectName string, poolName string, containerName string) string

GetContainerMountPoint returns the mountpoint of the given container. ${LXD_DIR}/storage-pools/<pool>/containers/[<project_name>_]<container_name>

func GetImageMountPoint

func GetImageMountPoint(poolName string, fingerprint string) string

GetImageMountPoint returns the mountpoint of the given image. ${LXD_DIR}/storage-pools/<pool>/images/<fingerprint>

func GetSnapshotMountPoint

func GetSnapshotMountPoint(projectName, poolName string, snapshotName string) string

GetSnapshotMountPoint returns the mountpoint of the given container snapshot. ${LXD_DIR}/storage-pools/<pool>/containers-snapshots/<snapshot_name>

func GetStoragePoolMountPoint

func GetStoragePoolMountPoint(poolName string) string

GetStoragePoolMountPoint returns the mountpoint of the given pool. {LXD_DIR}/storage-pools/<pool> Deprecated, use GetPoolMountPath in storage/drivers package.

func GetStoragePoolVolumeSnapshotMountPoint

func GetStoragePoolVolumeSnapshotMountPoint(poolName string, snapshotName string) string

GetStoragePoolVolumeSnapshotMountPoint returns the mountpoint of the given pool volume snapshot. ${LXD_DIR}/storage-pools/<pool>/custom-snapshots/<custom volume name>/<snapshot name>

func ImageUnpack

func ImageUnpack(imageFile string, vol drivers.Volume, destBlockFile string, blockBackend, runningInUserns bool, tracker *ioprogress.ProgressTracker) (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, op *operations.Operation) (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 InstanceImportingFilePath

func InstanceImportingFilePath(instanceType instancetype.Type, poolName, projectName, instanceName string) string

InstanceImportingFilePath returns the file path used to indicate an instance import is in progress. This marker file is created when using `lxd import` to import an instance that exists on the storage device but does not exist in the LXD database. The presence of this file causes the instance not to be removed from the storage device if the import should fail for some reason.

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 volume type.

func RenderSnapshotUsage

func RenderSnapshotUsage(s *state.State, snapInst instance.Instance) func(response interface{}) 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 ValidName

func ValidName(value string) error

ValidName validates the provided name, and returns an error if it's not a valid storage name.

func VolumeContentTypeNameToContentType

func VolumeContentTypeNameToContentType(contentTypeName string) (int, error)

VolumeContentTypeNameToContentType converts volume content type string internal code.

func VolumeContentTypeToDBContentType

func VolumeContentTypeToDBContentType(contentType drivers.ContentType) (int, error)

VolumeContentTypeToDBContentType converts volume type to internal code.

func VolumeDBContentTypeToContentType

func VolumeDBContentTypeToContentType(volDBType int) (drivers.ContentType, error)

VolumeDBContentTypeToContentType converts internal content type DB code to driver representation.

func VolumeDBCreate

func VolumeDBCreate(s *state.State, project, poolName, volumeName, volumeDescription, volumeTypeName string, snapshot bool, volumeConfig map[string]string, expiryDate time.Time, contentTypeName string) error

VolumeDBCreate creates a volume in the database.

func VolumeDBTypeToType

func VolumeDBTypeToType(volDBType int) (drivers.VolumeType, error)

VolumeDBTypeToType converts internal volume type DB code to driver representation.

func VolumeFillDefault

func VolumeFillDefault(config map[string]string, parentPool *api.StoragePool) error

VolumeFillDefault fills default settings into a volume config.

func VolumePropertiesTranslate

func VolumePropertiesTranslate(targetConfig map[string]string, targetParentPoolDriver string) (map[string]string, error)

VolumePropertiesTranslate validates the supplied volume config and removes any keys that are not suitable for the volume's driver type.

func VolumeSnapshotsGet

func VolumeSnapshotsGet(s *state.State, projectName string, pool string, volume string, volType int) ([]db.StorageVolumeArgs, error)

VolumeSnapshotsGet returns a list of snapshots of the form <volume>/<snapshot-name>.

func VolumeTypeNameToType

func VolumeTypeNameToType(volumeTypeName string) (int, error)

VolumeTypeNameToType converts a volume type string to internal code.

func VolumeTypeToDBType

func VolumeTypeToDBType(volType drivers.VolumeType) (int, error)

VolumeTypeToDBType converts volume type to internal 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 VolumeUsedByInstancesGet

func VolumeUsedByInstancesGet(s *state.State, projectName string, poolName string, volumeName string) ([]string, error)

VolumeUsedByInstancesGet gets a list of instance names using a volume.

func VolumeUsedByRunningInstancesWithProfilesGet

func VolumeUsedByRunningInstancesWithProfilesGet(s *state.State, projectName string, poolName string, volumeName string, volumeTypeName string, runningOnly bool) ([]string, error)

VolumeUsedByRunningInstancesWithProfilesGet gets list of running instances using a volume.

func VolumeValidateConfig

func VolumeValidateConfig(s *state.State, volName string, volType drivers.VolumeType, config map[string]string, parentPool *api.StoragePool) error

VolumeValidateConfig validations volume config. Deprecated.

Types

type Pool

type Pool interface {
	// Pool.
	ID() int64
	Name() string
	Driver() drivers.Driver

	GetResources() (*api.ResourcesStoragePool, error)
	Delete(localOnly bool, op *operations.Operation) error
	Update(driverOnly bool, newDesc string, newConfig map[string]string, op *operations.Operation) error

	Mount() (bool, error)
	Unmount() (bool, error)

	ApplyPatch(name string) error

	// Instances.
	CreateInstance(inst instance.Instance, op *operations.Operation) error
	CreateInstanceFromBackup(srcBackup backup.Info, srcData io.ReadSeeker, op *operations.Operation) (func(instance.Instance) error, func(), error)
	CreateInstanceFromCopy(inst instance.Instance, src instance.Instance, snapshots bool, op *operations.Operation) error
	CreateInstanceFromImage(inst instance.Instance, fingerprint string, op *operations.Operation) error
	CreateInstanceFromMigration(inst instance.Instance, conn io.ReadWriteCloser, args migration.VolumeTargetArgs, op *operations.Operation) error
	RenameInstance(inst instance.Instance, newName string, op *operations.Operation) error
	DeleteInstance(inst instance.Instance, op *operations.Operation) error
	UpdateInstance(inst instance.Instance, newDesc string, newConfig map[string]string, op *operations.Operation) error
	UpdateInstanceBackupFile(inst instance.Instance, op *operations.Operation) error
	CheckInstanceBackupFileSnapshots(backupConf *backup.Config, projectName string, deleteMissing bool, op *operations.Operation) ([]*api.InstanceSnapshot, error)

	MigrateInstance(inst instance.Instance, conn io.ReadWriteCloser, args *migration.VolumeSourceArgs, op *operations.Operation) error
	RefreshInstance(inst instance.Instance, src instance.Instance, srcSnapshots []instance.Instance, op *operations.Operation) error
	BackupInstance(inst instance.Instance, tarWriter *instancewriter.InstanceTarWriter, optimized bool, snapshots bool, op *operations.Operation) error

	GetInstanceUsage(inst instance.Instance) (int64, error)
	SetInstanceQuota(inst instance.Instance, size string, op *operations.Operation) error

	MountInstance(inst instance.Instance, op *operations.Operation) (bool, error)
	UnmountInstance(inst instance.Instance, op *operations.Operation) (bool, error)
	GetInstanceDisk(inst instance.Instance) (string, error)

	// Instance snapshots.
	CreateInstanceSnapshot(inst instance.Instance, src instance.Instance, op *operations.Operation) error
	RenameInstanceSnapshot(inst instance.Instance, newName string, op *operations.Operation) error
	DeleteInstanceSnapshot(inst instance.Instance, op *operations.Operation) error
	RestoreInstanceSnapshot(inst instance.Instance, src instance.Instance, op *operations.Operation) error
	MountInstanceSnapshot(inst instance.Instance, op *operations.Operation) (bool, error)
	UnmountInstanceSnapshot(inst instance.Instance, op *operations.Operation) (bool, error)
	UpdateInstanceSnapshot(inst instance.Instance, newDesc string, newConfig map[string]string, op *operations.Operation) error

	// Images.
	EnsureImage(fingerprint string, op *operations.Operation) error
	DeleteImage(fingerprint string, op *operations.Operation) error
	UpdateImage(fingerprint string, newDesc string, newConfig map[string]string, op *operations.Operation) error

	// Custom volumes.
	CreateCustomVolume(projectName string, volName string, desc string, config map[string]string, contentType drivers.ContentType, op *operations.Operation) error
	CreateCustomVolumeFromCopy(projectName string, volName, desc string, config map[string]string, srcPoolName, srcVolName string, srcVolOnly bool, op *operations.Operation) error
	UpdateCustomVolume(projectName string, volName string, newDesc string, newConfig map[string]string, op *operations.Operation) error
	RenameCustomVolume(projectName string, volName string, newVolName string, op *operations.Operation) error
	DeleteCustomVolume(projectName string, volName string, op *operations.Operation) error
	GetCustomVolumeDisk(projectName string, volName string) (string, error)
	GetCustomVolumeUsage(projectName string, volName string) (int64, error)
	MountCustomVolume(projectName string, volName string, op *operations.Operation) (bool, error)
	UnmountCustomVolume(projectName string, volName string, op *operations.Operation) (bool, error)

	// Custom volume snapshots.
	CreateCustomVolumeSnapshot(projectName string, volName string, newSnapshotName string, newExpiryDate time.Time, op *operations.Operation) error
	RenameCustomVolumeSnapshot(projectName string, volName string, newSnapshotName string, op *operations.Operation) error
	DeleteCustomVolumeSnapshot(projectName string, volName string, op *operations.Operation) error
	UpdateCustomVolumeSnapshot(projectName string, volName string, newDesc string, newConfig map[string]string, newExpiryDate time.Time, op *operations.Operation) error
	RestoreCustomVolume(projectName string, volName string, snapshotName string, op *operations.Operation) error

	// Custom volume migration.
	MigrationTypes(contentType drivers.ContentType, refresh bool) []migration.Type
	CreateCustomVolumeFromMigration(projectName string, conn io.ReadWriteCloser, args migration.VolumeTargetArgs, op *operations.Operation) error
	MigrateCustomVolume(projectName string, conn io.ReadWriteCloser, args *migration.VolumeSourceArgs, op *operations.Operation) error

	// Custom volume backups.
	BackupCustomVolume(projectName string, volName string, tarWriter *instancewriter.InstanceTarWriter, optimized bool, snapshots bool, op *operations.Operation) error
	CreateCustomVolumeFromBackup(srcBackup backup.Info, srcData io.ReadSeeker, op *operations.Operation) error
}

Pool represents a LXD storage pool.

func CreatePool

func CreatePool(state *state.State, poolID int64, dbPool *api.StoragePoolsPost, localOnly bool, op *operations.Operation) (Pool, error)

CreatePool creates a new storage pool on disk and returns a Pool interface. If the pool's driver is not recognised then drivers.ErrUnknownDriver is returned.

func GetPoolByInstance

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

GetPoolByInstance 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.ErrNotImplemented is returned.

func GetPoolByName

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

GetPoolByName 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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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