Documentation ¶
Index ¶
- Constants
- Variables
- func BucketDBCreate(ctx context.Context, pool Pool, projectName string, memberSpecific bool, ...) (int64, error)
- func BucketDBDelete(ctx context.Context, pool Pool, bucketID int64) error
- func BucketDBGet(pool Pool, projectName string, bucketName string, memberSpecific bool) (*db.StorageBucket, error)
- func CompareSnapshots(sourceSnapshots []ComparableSnapshot, targetSnapshots []ComparableSnapshot) ([]int, []int)
- func ConfigDiff(oldConfig map[string]string, newConfig map[string]string) ([]string, bool)
- func CreateContainerMountpoint(mountPoint string, mountPointSymlink string, privileged bool) error
- func CreateSnapshotMountpoint(snapshotMountpoint string, snapshotsSymlinkTarget string, ...) error
- func DiskVolumeSourceParse(source string) (volType drivers.VolumeType, dbVolType int, volTypeName string, volName string, ...)
- func FallbackMigrationType(contentType drivers.ContentType) migration.MigrationFSType
- func GetImageMountPoint(poolName string, fingerprint string) string
- func GetPoolDefaultBlockSize(s *state.State, poolName string) (string, error)
- func GetSnapshotMountPoint(projectName, poolName string, snapshotName string) string
- func GetStoragePoolMountPoint(poolName string) string
- func GetStoragePoolVolumeSnapshotMountPoint(poolName string, snapshotName string) string
- func ImageUnpack(imageFile string, vol drivers.Volume, destBlockFile string, sysOS *sys.OS, ...) (int64, error)
- func InstanceContentType(inst instance.Instance) drivers.ContentType
- func InstanceDiskBlockSize(pool Pool, inst instance.Instance, op *operations.Operation) (int64, error)
- func InstanceImportingFilePath(instanceType instancetype.Type, poolName, projectName, instanceName string) string
- func InstancePath(instanceType instancetype.Type, projectName, instanceName string, ...) string
- func InstanceTypeToVolumeType(instType instancetype.Type) (drivers.VolumeType, error)
- func InstanceUnmount(pool Pool, inst instance.Instance, op *operations.Operation) error
- func IsAvailable(poolName string) bool
- func Patch(s *state.State, patchName string) error
- func RenderSnapshotUsage(s *state.State, snapInst instance.Instance) func(response any) error
- func UsedBy(ctx context.Context, s *state.State, pool Pool, firstOnly bool, ...) ([]string, error)
- func ValidVolumeName(volumeName string) error
- func VolumeContentTypeNameToContentType(contentTypeName string) (int, error)
- func VolumeContentTypeToDBContentType(contentType drivers.ContentType) (int, error)
- func VolumeDBContentTypeToContentType(volDBType int) (drivers.ContentType, error)
- func VolumeDBCreate(pool Pool, projectName string, volumeName string, volumeDescription string, ...) error
- func VolumeDBDelete(pool Pool, projectName string, volumeName string, ...) error
- func VolumeDBGet(pool Pool, projectName string, volumeName string, ...) (*db.StorageVolume, error)
- func VolumeDBSnapshotsGet(pool Pool, projectName string, volume string, volumeType drivers.VolumeType) ([]db.StorageVolumeArgs, error)
- func VolumeDBTypeToType(volDBType int) (drivers.VolumeType, error)
- func VolumeTypeNameToDBType(volumeTypeName string) (int, error)
- func VolumeTypeToAPIInstanceType(volType drivers.VolumeType) (api.InstanceType, error)
- func VolumeTypeToDBType(volType drivers.VolumeType) (int, error)
- func VolumeUsedByDaemon(s *state.State, poolName string, volumeName string) (bool, error)
- func VolumeUsedByExclusiveRemoteInstancesWithProfiles(s *state.State, poolName string, projectName string, vol *api.StorageVolume) (*db.InstanceArgs, error)
- func VolumeUsedByInstanceDevices(s *state.State, poolName string, projectName string, vol *api.StorageVolume, ...) error
- func VolumeUsedByProfileDevices(s *state.State, poolName string, projectName string, vol *api.StorageVolume, ...) error
- type ComparableSnapshot
- type MountInfo
- type Pool
- func LoadByInstance(s *state.State, inst instance.Instance) (Pool, error)
- func LoadByName(s *state.State, name string) (Pool, error)
- func LoadByRecord(s *state.State, poolID int64, poolInfo api.StoragePool, ...) (Pool, error)
- func NewTemporary(state *state.State, info *api.StoragePool) (Pool, error)
- type Type
- type VolumeUsage
Constants ¶
const PoolIDTemporary = -1
PoolIDTemporary is used to indicate a temporary pool instance that is not in the database.
Variables ¶
var ErrBackupSnapshotsMismatch = fmt.Errorf("Backup snapshots mismatch")
ErrBackupSnapshotsMismatch is the "Backup snapshots mismatch" error.
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 ¶
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 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 ¶
ConfigDiff returns a diff of the provided configs. Additionally, it returns whether or not only user properties have been changed.
func CreateContainerMountpoint ¶
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 DiskVolumeSourceParse ¶
func DiskVolumeSourceParse(source string) (volType drivers.VolumeType, dbVolType int, volTypeName string, volName string, err error)
DiskVolumeSourceParse parses a disk device's `source` property when it refers to a storage volume.
func FallbackMigrationType ¶
func FallbackMigrationType(contentType drivers.ContentType) migration.MigrationFSType
FallbackMigrationType returns the fallback migration transport to use based on volume content type.
func GetImageMountPoint ¶
GetImageMountPoint returns the mountpoint of the given image. ${LXD_DIR}/storage-pools/<pool>/images/<fingerprint>.
func GetPoolDefaultBlockSize ¶
GetPoolDefaultBlockSize returns the default block size for the specified storage pool according to its driver.
func GetSnapshotMountPoint ¶
GetSnapshotMountPoint returns the mountpoint of the given container snapshot. ${LXD_DIR}/storage-pools/<pool>/containers-snapshots/<snapshot_name>.
func GetStoragePoolMountPoint ¶
GetStoragePoolMountPoint returns the mountpoint of the given pool. {LXD_DIR}/storage-pools/<pool> Deprecated, use GetPoolMountPath in storage/drivers package.
func GetStoragePoolVolumeSnapshotMountPoint ¶
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, 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 `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 storage driver volume type.
func InstanceUnmount ¶
InstanceUnmount unmounts an instance's storage volume (if not in use).
func IsAvailable ¶
IsAvailable checks if a pool is available.
func Patch ¶
Patch applies specified patch to all storage pools. All storage pools must be available locally before any storage pools are patched.
func RenderSnapshotUsage ¶
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 ValidVolumeName ¶
ValidVolumeName validates a volume name.
func VolumeContentTypeNameToContentType ¶
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 ¶
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 ¶
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 ¶
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 MountVolume(projectName string, volName string, volType drivers.VolumeType, op *operations.Operation) (*MountInfo, error) UnmountVolume(projectName string, volName string, volType drivers.VolumeType, op *operations.Operation) (bool, error) // 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 CreateInstanceFromConversion(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, 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 // 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 GetCustomVolumeUsage(projectName string, volName string) (*VolumeUsage, 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, newDescription 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 a LXD storage pool.
func LoadByInstance ¶
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 ¶
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 ¶
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 VolumeUsage ¶
VolumeUsage contains the used and total size of a volume.