storage

package
v0.0.0-...-04e5504 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2021 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const ContainersDirMode os.FileMode = 0711

ContainersDirMode represents the default permissions for the containers directory.

View Source
const CustomDirMode os.FileMode = 0711

CustomDirMode represents the default permissions for the custom directory.

View Source
const ImagesDirMode os.FileMode = 0700

ImagesDirMode represents the default permissions for the images directory.

View Source
const SnapshotsDirMode os.FileMode = 0700

SnapshotsDirMode represents the default permissions for the snapshots directory.

View Source
const StoragePoolsDirMode os.FileMode = 0711

StoragePoolsDirMode represents the default permissions for the storage pool directory.

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 := shared.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"}, shared.IsAny(value)
	},
	"security.shifted": func(value string) ([]string, error) {
		return SupportedPoolTypes, shared.IsBool(value)
	},
	"security.unmapped": func(value string) ([]string, error) {
		return SupportedPoolTypes, shared.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, shared.IsAny(value)
	},
	"volatile.idmap.next": func(value string) ([]string, error) {
		return SupportedPoolTypes, shared.IsAny(value)
	},
	"zfs.remove_snapshots": func(value string) ([]string, error) {
		err := shared.IsBool(value)
		if err != nil {
			return nil, err
		}

		return []string{"zfs"}, nil
	},
	"zfs.use_refquota": func(value string) ([]string, error) {
		err := shared.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()

View Source
var VolumeUsedByInstancesWithProfiles func(s *state.State, poolName string, volumeName string, volumeTypeName string, runningOnly bool) ([]string, error)

VolumeUsedByInstancesWithProfiles returns a slice containing the names of instances using a volume.

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 FSGenerateNewUUID

func FSGenerateNewUUID(fstype string, lvpath string) (string, error)

FSGenerateNewUUID generates a UUID for the given path for btrfs and xfs filesystems.

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 GetStoragePoolVolumeMountPoint

func GetStoragePoolVolumeMountPoint(poolName string, volumeName string) string

GetStoragePoolVolumeMountPoint returns the mountpoint of the given pool volume. ${LXD_DIR}/storage-pools/<pool>/custom/<storage_volume>

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 GetStorageResource

func GetStorageResource(path string) (*api.ResourcesStoragePool, error)

GetStorageResource returns the available resources of a given path.

func GrowFileSystem

func GrowFileSystem(fsType string, devPath string, mntpoint string) error

GrowFileSystem grows a filesystem if it is supported.

func ImageUnpack

func ImageUnpack(imageFile, destPath, destBlockFile string, blockBackend, runningInUserns bool, tracker *ioprogress.ProgressTracker) 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 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 LXDUsesPool

func LXDUsesPool(dbObj *db.Cluster, onDiskPoolName string, driver string, onDiskProperty string) (bool, string, error)

LXDUsesPool detect whether LXD already uses the given storage pool.

func ShrinkFileSystem

func ShrinkFileSystem(fsType string, devPath string, mntpoint string, byteSize int64) error

ShrinkFileSystem shrinks a filesystem if it is supported.

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 VolumeDBCreate

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

VolumeDBCreate creates a volume in the database.

func VolumeFillDefault

func VolumeFillDefault(name string, 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, 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 VolumeUsedByInstancesGet

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

VolumeUsedByInstancesGet gets a list of instance names using a volume.

func VolumeValidateConfig

func VolumeValidateConfig(s *state.State, name string, 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.InstanceConfig, 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, targetPath string, 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, newDesc string, newConfig map[string]string, op *operations.Operation) error

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

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

	// Custom volume migration.
	MigrationTypes(contentType drivers.ContentType, refresh bool) []migration.Type
	CreateCustomVolumeFromMigration(conn io.ReadWriteCloser, args migration.VolumeTargetArgs, op *operations.Operation) error
	MigrateCustomVolume(conn io.ReadWriteCloser, args *migration.VolumeSourceArgs, 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