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

Method CreateInstanceFromMigration

internal/server/storage/backend.go:1967–2259  ·  view source on GitHub ↗

CreateInstanceFromMigration receives an instance being migrated. The args.Name and args.Config fields are ignored and, instance properties are used instead.

(inst instance.Instance, conn io.ReadWriteCloser, args localMigration.VolumeTargetArgs, op *operations.Operation)

Source from the content-addressed store, hash-verified

1965// CreateInstanceFromMigration receives an instance being migrated.
1966// The args.Name and args.Config fields are ignored and, instance properties are used instead.
1967func (b *backend) CreateInstanceFromMigration(inst instance.Instance, conn io.ReadWriteCloser, args localMigration.VolumeTargetArgs, op *operations.Operation) error {
1968 l := b.logger.AddContext(logger.Ctx{"project": inst.Project().Name, "instance": inst.Name(), "args": fmt.Sprintf("%+v", args)})
1969 l.Debug("CreateInstanceFromMigration started")
1970 defer l.Debug("CreateInstanceFromMigration finished")
1971
1972 err := b.isStatusReady()
1973 if err != nil {
1974 return err
1975 }
1976
1977 if args.Config != nil {
1978 return errors.New("Migration VolumeTargetArgs.Config cannot be set for instances")
1979 }
1980
1981 volType, err := InstanceTypeToVolumeType(inst.Type())
1982 if err != nil {
1983 return err
1984 }
1985
1986 contentType := InstanceContentType(inst)
1987
1988 // Receive index header from source if applicable and respond confirming receipt.
1989 // This will also communicate the args.Refresh setting back to the source (in case it was changed by the
1990 // caller if the instance DB record already exists).
1991 srcInfo, err := b.migrationIndexHeaderReceive(l, args.IndexHeaderVersion, conn, args.Refresh)
1992 if err != nil {
1993 return err
1994 }
1995
1996 reverter := revert.New()
1997 defer reverter.Fail()
1998
1999 if !inst.IsSnapshot() && srcInfo.Config != nil && srcInfo.Config.Container != nil {
2000 // Create dependent volumes if they exist.
2001 cleanupDependentVols, err := b.createDependentVolumesFromMigration(inst, conn, args, srcInfo, op)
2002 if err != nil {
2003 return err
2004 }
2005
2006 reverter.Add(func() { cleanupDependentVols() })
2007 }
2008
2009 // Now that we got the source details, validate against the instance limits.
2010 _, rootDiskConf, err := internalInstance.GetRootDiskDevice(inst.ExpandedDevices().CloneNative())
2011 if err != nil {
2012 return err
2013 }
2014
2015 if rootDiskConf["size"] != "" {
2016 rootDiskConfBytes, err := units.ParseByteSizeString(rootDiskConf["size"])
2017 if err != nil {
2018 return err
2019 }
2020
2021 // Compare volume size with configured root size.
2022 // Add a 4MiB allowed extra to account for round to nearest extent (16k on ZFS, 4MiB on LVM).
2023 if args.VolumeSize > (rootDiskConfBytes + (4 * 1024 * 1024)) {
2024 return errors.New("The configured target instance root disk size is smaller than the migration source")

Callers 2

RefreshInstanceMethod · 0.95

Calls 15

isStatusReadyMethod · 0.95
GetVolumeMethod · 0.95
NameMethod · 0.95
imageFillerMethod · 0.95
EnsureImageMethod · 0.95
DeleteInstanceMethod · 0.95
ensureInstanceSymlinkMethod · 0.95

Tested by

no test coverage detected