[lxc-devel] [lxd/master] Refresh handling in MigrationTypes

stgraber on Github lxc-bot at linuxcontainers.org
Fri Dec 13 04:45:35 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 301 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20191212/2d2573d5/attachment.bin>
-------------- next part --------------
From a5afa1241ba99c5602b0cb9e694c68626a64635e Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Wed, 4 Dec 2019 20:43:12 +0100
Subject: [PATCH 1/3] lxd/storage: Add refresh to MigrationTypes

This adds the refresh argument to the MigrationTypes function. Some
drivers use different migration types based on the action they are
performing, so they might use a different type when performing a
refresh.

Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
 lxd/storage/backend_lxd.go    | 16 ++++++++--------
 lxd/storage/backend_mock.go   |  2 +-
 lxd/storage/pool_interface.go |  2 +-
 3 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/lxd/storage/backend_lxd.go b/lxd/storage/backend_lxd.go
index 06696e0fb6..f4cd4e8650 100644
--- a/lxd/storage/backend_lxd.go
+++ b/lxd/storage/backend_lxd.go
@@ -53,8 +53,8 @@ func (b *lxdBackend) Driver() drivers.Driver {
 
 // MigrationTypes returns the migration transport method preferred when sending a migration,
 // based on the migration method requested by the driver's ability.
-func (b *lxdBackend) MigrationTypes(contentType drivers.ContentType) []migration.Type {
-	return b.driver.MigrationTypes(contentType)
+func (b *lxdBackend) MigrationTypes(contentType drivers.ContentType, refresh bool) []migration.Type {
+	return b.driver.MigrationTypes(contentType, refresh)
 }
 
 // create creates the storage pool layout on the storage device.
@@ -567,9 +567,9 @@ func (b *lxdBackend) CreateInstanceFromCopy(inst instance.Instance, src instance
 		aEnd, bEnd := memorypipe.NewPipePair()
 
 		// Negotiate the migration type to use.
-		offeredTypes := srcPool.MigrationTypes(contentType)
+		offeredTypes := srcPool.MigrationTypes(contentType, false)
 		offerHeader := migration.TypesToHeader(offeredTypes...)
-		migrationType, err := migration.MatchTypes(offerHeader, migration.MigrationFSType_RSYNC, b.MigrationTypes(contentType))
+		migrationType, err := migration.MatchTypes(offerHeader, migration.MigrationFSType_RSYNC, b.MigrationTypes(contentType, false))
 		if err != nil {
 			return fmt.Errorf("Failed to negotiate copy migration type: %v", err)
 		}
@@ -708,9 +708,9 @@ func (b *lxdBackend) RefreshInstance(inst instance.Instance, src instance.Instan
 		aEnd, bEnd := memorypipe.NewPipePair()
 
 		// Negotiate the migration type to use.
-		offeredTypes := srcPool.MigrationTypes(contentType)
+		offeredTypes := srcPool.MigrationTypes(contentType, true)
 		offerHeader := migration.TypesToHeader(offeredTypes...)
-		migrationType, err := migration.MatchTypes(offerHeader, migration.MigrationFSType_RSYNC, b.MigrationTypes(contentType))
+		migrationType, err := migration.MatchTypes(offerHeader, migration.MigrationFSType_RSYNC, b.MigrationTypes(contentType, true))
 		if err != nil {
 			return fmt.Errorf("Failed to negotiate copy migration type: %v", err)
 		}
@@ -1801,9 +1801,9 @@ func (b *lxdBackend) CreateCustomVolumeFromCopy(volName, desc string, config map
 	aEnd, bEnd := memorypipe.NewPipePair()
 
 	// Negotiate the migration type to use.
-	offeredTypes := srcPool.MigrationTypes(drivers.ContentTypeFS)
+	offeredTypes := srcPool.MigrationTypes(drivers.ContentTypeFS, false)
 	offerHeader := migration.TypesToHeader(offeredTypes...)
-	migrationType, err := migration.MatchTypes(offerHeader, migration.MigrationFSType_RSYNC, b.MigrationTypes(drivers.ContentTypeFS))
+	migrationType, err := migration.MatchTypes(offerHeader, migration.MigrationFSType_RSYNC, b.MigrationTypes(drivers.ContentTypeFS, false))
 	if err != nil {
 		return fmt.Errorf("Failed to neogotiate copy migration type: %v", err)
 	}
diff --git a/lxd/storage/backend_mock.go b/lxd/storage/backend_mock.go
index 74fdeb9427..9cc026d611 100644
--- a/lxd/storage/backend_mock.go
+++ b/lxd/storage/backend_mock.go
@@ -31,7 +31,7 @@ func (b *mockBackend) Driver() drivers.Driver {
 	return nil
 }
 
-func (b *mockBackend) MigrationTypes(contentType drivers.ContentType) []migration.Type {
+func (b *mockBackend) MigrationTypes(contentType drivers.ContentType, refresh bool) []migration.Type {
 	return []migration.Type{
 		{
 			FSType:   migration.MigrationFSType_RSYNC,
diff --git a/lxd/storage/pool_interface.go b/lxd/storage/pool_interface.go
index a66c61aa74..279d0db79e 100644
--- a/lxd/storage/pool_interface.go
+++ b/lxd/storage/pool_interface.go
@@ -74,7 +74,7 @@ type Pool interface {
 	RestoreCustomVolume(volName string, snapshotName string, op *operations.Operation) error
 
 	// Custom volume migration.
-	MigrationTypes(contentType drivers.ContentType) []migration.Type
+	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
 }

From 580c7a6f779bf15265bd26d7fb75d1404ed6691b Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Wed, 4 Dec 2019 20:45:58 +0100
Subject: [PATCH 2/3] lxd/storage/drivers: Add refresh to MigrationTypes

This adds the refresh argument to the MigrationTypes function. Some
drivers use different migration types based on the action they are
performing, so they might use a different type when performing a
refresh.

Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
 lxd/storage/drivers/driver_cephfs.go | 2 +-
 lxd/storage/drivers/driver_common.go | 2 +-
 lxd/storage/drivers/interface.go     | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/lxd/storage/drivers/driver_cephfs.go b/lxd/storage/drivers/driver_cephfs.go
index 26e6f20e4b..c2ede30ed0 100644
--- a/lxd/storage/drivers/driver_cephfs.go
+++ b/lxd/storage/drivers/driver_cephfs.go
@@ -977,7 +977,7 @@ func (d *cephfs) RestoreBackupVolume(vol Volume, snapshots []string, srcData io.
 	return nil, nil, ErrNotImplemented
 }
 
-func (d *cephfs) MigrationTypes(contentType ContentType) []migration.Type {
+func (d *cephfs) MigrationTypes(contentType ContentType, refresh bool) []migration.Type {
 	if contentType != ContentTypeFS {
 		return nil
 	}
diff --git a/lxd/storage/drivers/driver_common.go b/lxd/storage/drivers/driver_common.go
index 224f35209d..a0cfb0173d 100644
--- a/lxd/storage/drivers/driver_common.go
+++ b/lxd/storage/drivers/driver_common.go
@@ -81,7 +81,7 @@ func (d *common) validateVolume(vol Volume, driverRules map[string]func(value st
 
 // MigrationType returns the type of transfer methods to be used when doing migrations between pools
 // in preference order.
-func (d *common) MigrationTypes(contentType ContentType) []migration.Type {
+func (d *common) MigrationTypes(contentType ContentType, refresh bool) []migration.Type {
 	if contentType != ContentTypeFS {
 		return nil
 	}
diff --git a/lxd/storage/drivers/interface.go b/lxd/storage/drivers/interface.go
index 4dd46e7669..31b42d925c 100644
--- a/lxd/storage/drivers/interface.go
+++ b/lxd/storage/drivers/interface.go
@@ -69,7 +69,7 @@ type Driver interface {
 	RestoreVolume(vol Volume, snapshotName string, op *operations.Operation) error
 
 	// Migration.
-	MigrationTypes(contentType ContentType) []migration.Type
+	MigrationTypes(contentType ContentType, refresh bool) []migration.Type
 	MigrateVolume(vol Volume, conn io.ReadWriteCloser, volSrcArgs migration.VolumeSourceArgs, op *operations.Operation) error
 	CreateVolumeFromMigration(vol Volume, conn io.ReadWriteCloser, volTargetArgs migration.VolumeTargetArgs, preFiller *VolumeFiller, op *operations.Operation) error
 

From ed257e61e545572f8da1f295a9e4f451beed00dd Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Wed, 4 Dec 2019 20:44:06 +0100
Subject: [PATCH 3/3] lxd: Update call to MigrationTypes

This updates calls to MigrationTypes by adding a refresh argument.

Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
 lxd/migrate_container.go       | 8 ++++++--
 lxd/migrate_storage_volumes.go | 8 ++++++--
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/lxd/migrate_container.go b/lxd/migrate_container.go
index aba286de82..208041a654 100644
--- a/lxd/migrate_container.go
+++ b/lxd/migrate_container.go
@@ -350,7 +350,11 @@ func (s *migrationSourceWs) Do(state *state.State, migrateOp *operations.Operati
 			return err
 		}
 
-		poolMigrationTypes = pool.MigrationTypes(storagePools.InstanceContentType(s.instance))
+		// The refresh argument passed to MigrationTypes() is always set
+		// to false here. The migration source/sender doesn't need to care whether
+		// or not it's doing a refresh as the migration sink/receiver will know
+		// this, and adjust the migration types accordingly.
+		poolMigrationTypes = pool.MigrationTypes(storagePools.InstanceContentType(s.instance), false)
 		if len(poolMigrationTypes) < 0 {
 			return fmt.Errorf("No source migration types available")
 		}
@@ -941,7 +945,7 @@ func (c *migrationSink) Do(state *state.State, migrateOp *operations.Operation)
 		// Extract the source's migration type and then match it against our pool's
 		// supported types and features. If a match is found the combined features list
 		// will be sent back to requester.
-		respType, err := migration.MatchTypes(offerHeader, migration.MigrationFSType_RSYNC, pool.MigrationTypes(storagePools.InstanceContentType(c.src.instance)))
+		respType, err := migration.MatchTypes(offerHeader, migration.MigrationFSType_RSYNC, pool.MigrationTypes(storagePools.InstanceContentType(c.src.instance), c.refresh))
 		if err != nil {
 			return err
 		}
diff --git a/lxd/migrate_storage_volumes.go b/lxd/migrate_storage_volumes.go
index 5b2918bef0..f78ffa2119 100644
--- a/lxd/migrate_storage_volumes.go
+++ b/lxd/migrate_storage_volumes.go
@@ -50,7 +50,11 @@ func (s *migrationSourceWs) DoStorage(state *state.State, poolName string, volNa
 			return err
 		}
 
-		poolMigrationTypes = pool.MigrationTypes(storageDrivers.ContentTypeFS)
+		// The refresh argument passed to MigrationTypes() is always set
+		// to false here. The migration source/sender doesn't need to care whether
+		// or not it's doing a refresh as the migration sink/receiver will know
+		// this, and adjust the migration types accordingly.
+		poolMigrationTypes = pool.MigrationTypes(storageDrivers.ContentTypeFS, false)
 		if len(poolMigrationTypes) < 0 {
 			return fmt.Errorf("No source migration types available")
 		}
@@ -342,7 +346,7 @@ func (c *migrationSink) DoStorage(state *state.State, poolName string, req *api.
 		// Extract the source's migration type and then match it against our pool's
 		// supported types and features. If a match is found the combined features list
 		// will be sent back to requester.
-		respType, err := migration.MatchTypes(offerHeader, migration.MigrationFSType_RSYNC, pool.MigrationTypes(storageDrivers.ContentTypeFS))
+		respType, err := migration.MatchTypes(offerHeader, migration.MigrationFSType_RSYNC, pool.MigrationTypes(storageDrivers.ContentTypeFS, c.refresh))
 		if err != nil {
 			return err
 		}


More information about the lxc-devel mailing list