MCPcopy
hub / github.com/lxc/incus / CreateCustomVolumeFromCopy

Method CreateCustomVolumeFromCopy

internal/server/storage/backend.go:4964–5216  ·  view source on GitHub ↗

CreateCustomVolumeFromCopy creates a custom volume from an existing custom volume. It copies the snapshots from the source volume by default, but can be disabled if requested.

(projectName string, srcProjectName string, volName string, desc string, config map[string]string, srcPoolName, srcVolName string, snapshots bool, op *operations.Operation)

Source from the content-addressed store, hash-verified

4962// CreateCustomVolumeFromCopy creates a custom volume from an existing custom volume.
4963// It copies the snapshots from the source volume by default, but can be disabled if requested.
4964func (b *backend) CreateCustomVolumeFromCopy(projectName string, srcProjectName string, volName string, desc string, config map[string]string, srcPoolName, srcVolName string, snapshots bool, op *operations.Operation) error {
4965 l := b.logger.AddContext(logger.Ctx{"project": projectName, "srcProjectName": srcProjectName, "volName": volName, "desc": desc, "config": config, "srcPoolName": srcPoolName, "srcVolName": srcVolName, "snapshots": snapshots})
4966 l.Debug("CreateCustomVolumeFromCopy started")
4967 defer l.Debug("CreateCustomVolumeFromCopy finished")
4968
4969 err := b.isStatusReady()
4970 if err != nil {
4971 return err
4972 }
4973
4974 if srcProjectName == "" {
4975 srcProjectName = projectName
4976 }
4977
4978 // Setup the source pool backend instance.
4979 var srcPool Pool
4980 if b.name == srcPoolName {
4981 srcPool = b // Source and target are in the same pool so share pool var.
4982 } else {
4983 // Source is in a different pool to target, so load the pool.
4984 srcPool, err = LoadByName(b.state, srcPoolName)
4985 if err != nil {
4986 return err
4987 }
4988 }
4989
4990 // Check source volume exists and is custom type, and get its config.
4991 srcConfig, err := srcPool.GenerateCustomVolumeBackupConfig(srcProjectName, srcVolName, snapshots, op)
4992 if err != nil {
4993 return fmt.Errorf("Failed generating volume copy config: %w", err)
4994 }
4995
4996 // Use the source volume's config if not supplied.
4997 if config == nil {
4998 config = srcConfig.Volume.Config
4999 }
5000
5001 // Use the source volume's description if not supplied.
5002 if desc == "" {
5003 desc = srcConfig.Volume.Description
5004 }
5005
5006 contentDBType, err := VolumeContentTypeNameToContentType(srcConfig.Volume.ContentType)
5007 if err != nil {
5008 return err
5009 }
5010
5011 // Get the source volume's content type.
5012 contentType, err := VolumeDBContentTypeToContentType(contentDBType)
5013 if err != nil {
5014 return err
5015 }
5016
5017 storagePoolSupported := slices.Contains(b.Driver().Info().VolumeTypes, drivers.VolumeTypeCustom)
5018
5019 if !storagePoolSupported {
5020 return errors.New("Storage pool does not support custom volume type")
5021 }

Callers

nothing calls this directly

Calls 15

isStatusReadyMethod · 0.95
DriverMethod · 0.95
GetVolumeMethod · 0.95
GetVolumeMethod · 0.95
NameMethod · 0.95
MigrationTypesMethod · 0.95
MigrationTypesMethod · 0.95
MigrateCustomVolumeMethod · 0.95
NameMethod · 0.95
NewFunction · 0.92

Tested by

no test coverage detected