storage

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: Apache-2.0 Imports: 62 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 = 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.

Functions

func BucketDBCreate

func BucketDBCreate(ctx context.Context, pool Pool, projectName string, memberSpecific bool, 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 BucketDBGet

func BucketDBGet(pool Pool, projectName string, bucketName string, memberSpecific bool) (*db.StorageBucket, error)

BucketDBGet loads a bucket from the database.

func BucketKeysDBGet added in v0.6.0

func BucketKeysDBGet(pool Pool, bucketID int64) ([]*db.StorageBucketKey, error)

BucketKeysDBGet loads the keys for a bucket from the database.

func CompareSnapshots

func CompareSnapshots(sourceSnapshots []ComparableSnapshot, targetSnapshots []ComparableSnapshot) ([]int, []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 GetImageMountPoint

func GetImageMountPoint(poolName string, fingerprint string) string

GetImageMountPoint returns the mountpoint of the given image. ${INCUS_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. ${INCUS_DIR}/storage-pools/<pool>/containers-snapshots/<snapshot_name>.

func GetStoragePoolMountPoint

func GetStoragePoolMountPoint(poolName string) string

GetStoragePoolMountPoint returns the mountpoint of the given pool. {INCUS_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. ${INCUS_DIR}/storage-pools/<pool>/custom-snapshots/<custom volume name>/<snapshot name>.

func ImageUnpack

func ImageUnpack(imageFile string, vol drivers.Volume, destBlockFile string, sysOS *sys.OS, allowUnsafeResize 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 `incusd import` to import an instance that exists on the storage device but does not exist in the Incus 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 storage driver volume type.

func InstanceUnmount

func InstanceUnmount(pool Pool, inst instance.Instance, op *operations.Operation) 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 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 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(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 int) (drivers.VolumeType, error)

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

func VolumeTypeNameToDBType

func VolumeTypeNameToDBType(volumeTypeName string) (int, error)

VolumeTypeNameToDBType converts a volume type string to internal volume type DB code.

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) (int, 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 {
	DiskPath  string                               // 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, op *operations.Operation) (*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, op *operations.Operation) error
	Update(clientType request.ClientType, newDesc string, newConfig map[string]string, op *operations.Operation) error

	Create(clientType request.ClientType, op *operations.Operation) 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, op *operations.Operation) error
	CreateInstanceFromBackup(srcBackup backup.Info, srcData io.ReadSeeker, op *operations.Operation) (func(instance.Instance) error, revert.Hook, error)
	CreateInstanceFromCopy(inst instance.Instance, src instance.Instance, snapshots bool, allowInconsistent 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, snapshots bool, op *operations.Operation) error
	GenerateInstanceBackupConfig(inst instance.Instance, snapshots bool, op *operations.Operation) (*backupConfig.Config, error)
	CheckInstanceBackupFileSnapshots(backupConf *backupConfig.Config, projectName string, deleteMissing bool, op *operations.Operation) ([]*api.InstanceSnapshot, error)
	ImportInstance(inst instance.Instance, poolVol *backupConfig.Config, op *operations.Operation) (revert.Hook, error)
	CleanupInstancePaths(inst instance.Instance, op *operations.Operation) 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, allowInconsistent bool, op *operations.Operation) error
	BackupInstance(inst instance.Instance, tarWriter *instancewriter.InstanceTarWriter, optimized bool, snapshots bool, op *operations.Operation) error

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

	MountInstance(inst instance.Instance, op *operations.Operation) (*MountInfo, error)
	UnmountInstance(inst instance.Instance, op *operations.Operation) 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) (*MountInfo, error)
	UnmountInstanceSnapshot(inst instance.Instance, op *operations.Operation) 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

	// Buckets.
	CreateBucket(projectName string, bucket api.StorageBucketsPost, op *operations.Operation) error
	UpdateBucket(projectName string, bucketName string, bucket api.StorageBucketPut, op *operations.Operation) error
	DeleteBucket(projectName string, bucketName string, op *operations.Operation) error
	ImportBucket(projectName string, poolVol *backupConfig.Config, op *operations.Operation) (revert.Hook, error)
	CreateBucketKey(projectName string, bucketName string, key api.StorageBucketKeysPost, op *operations.Operation) (*api.StorageBucketKey, error)
	UpdateBucketKey(projectName string, bucketName string, keyName string, key api.StorageBucketKeyPut, op *operations.Operation) error
	DeleteBucketKey(projectName string, bucketName string, keyName string, op *operations.Operation) error
	ActivateBucket(projectName string, bucketName string, op *operations.Operation) (*miniod.Process, error)
	GetBucketURL(bucketName string) *url.URL
	GenerateBucketBackupConfig(projectName string, bucketName string, op *operations.Operation) (*backupConfig.Config, error)
	BackupBucket(projectName string, bucketName string, tarWriter *instancewriter.InstanceTarWriter, op *operations.Operation) error
	CreateBucketFromBackup(srcBackup backup.Info, srcData io.ReadSeeker, 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, srcProjectName string, volName, desc string, config map[string]string, srcPoolName, srcVolName string, snapshots 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) (*VolumeUsage, error)
	MountCustomVolume(projectName string, volName string, op *operations.Operation) (*MountInfo, error)
	UnmountCustomVolume(projectName string, volName string, op *operations.Operation) (bool, error)
	ImportCustomVolume(projectName string, poolVol *backupConfig.Config, op *operations.Operation) (revert.Hook, error)
	RefreshCustomVolume(projectName string, srcProjectName string, volName, desc string, config map[string]string, srcPoolName, srcVolName string, snapshots bool, op *operations.Operation) error
	GenerateCustomVolumeBackupConfig(projectName string, volName string, snapshots bool, op *operations.Operation) (*backupConfig.Config, error)
	CreateCustomVolumeFromISO(projectName string, volName string, srcData io.ReadSeeker, size int64, op *operations.Operation) 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, copySnapshots 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

	// Storage volume recovery.
	ListUnknownVolumes(op *operations.Operation) (map[string][]*backupConfig.Config, error)
}

Pool represents an Incus 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 an Incus 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
s3

Jump to

Keyboard shortcuts

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