The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/6471

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
If source volume and target volume are on the same storage pool then don't use migration system, and instead use driver's CreateVolumeFromCopy() directly.

Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
From 9de95a95fe97257b74209e0728de4eae44926ff0 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parr...@canonical.com>
Date: Tue, 19 Nov 2019 17:06:18 +0000
Subject: [PATCH] lxd/storage/backend/lxd: Adds same pool optimisation to
 CreateCustomVolumeFromCopy

If source volume and target volume are on the same storage pool then don't use 
migration system, and instead use driver's CreateVolumeFromCopy() directly.

Signed-off-by: Thomas Parrott <thomas.parr...@canonical.com>
---
 lxd/storage/backend_lxd.go | 54 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)

diff --git a/lxd/storage/backend_lxd.go b/lxd/storage/backend_lxd.go
index 3a82bf6ea2..2c58d69dea 100644
--- a/lxd/storage/backend_lxd.go
+++ b/lxd/storage/backend_lxd.go
@@ -1006,6 +1006,60 @@ func (b *lxdBackend) CreateCustomVolumeFromCopy(volName, 
desc string, config map
                }
        }
 
+       // If the source and target are in the same pool then use 
CreateVolumeFromCopy rather than
+       // migration system as it will be quicker.
+       if srcPool == b {
+               // Create slice to record DB volumes created if revert needed 
later.
+               revertDBVolumes := []string{}
+               defer func() {
+                       // Remove any DB volume rows created if we are 
reverting.
+                       for _, volName := range revertDBVolumes {
+                               
b.state.Cluster.StoragePoolVolumeDelete("default", volName, 
db.StoragePoolVolumeTypeCustom, b.ID())
+                       }
+               }()
+
+               vol := b.newVolume(drivers.VolumeTypeCustom, 
drivers.ContentTypeFS, volName, config)
+               srcVol := b.newVolume(drivers.VolumeTypeCustom, 
drivers.ContentTypeFS, srcVolName, srcVolRow.Config)
+
+               // Check the supplied config and remove any fields not relevant 
for pool type.
+               err := b.driver.ValidateVolume(vol, true)
+               if err != nil {
+                       return err
+               }
+
+               // Create database entry for new storage volume.
+               err = VolumeDBCreate(b.state, b.name, volName, desc, 
db.StoragePoolVolumeTypeNameCustom, false, config)
+               if err != nil {
+                       return err
+               }
+
+               revertDBVolumes = append(revertDBVolumes, volName)
+
+               if len(snapshotNames) > 0 {
+                       for _, snapName := range snapshotNames {
+                               newSnapshotName := 
drivers.GetSnapshotVolumeName(volName, snapName)
+
+                               // Create database entry for new storage volume 
snapshot.
+                               err = VolumeDBCreate(b.state, b.name, 
newSnapshotName, desc, db.StoragePoolVolumeTypeNameCustom, true, config)
+                               if err != nil {
+                                       return err
+                               }
+
+                               revertDBVolumes = append(revertDBVolumes, 
newSnapshotName)
+                       }
+               }
+
+               err = b.driver.CreateVolumeFromCopy(vol, srcVol, !srcVolOnly, 
op)
+               if err != nil {
+                       return err
+               }
+
+               revertDBVolumes = nil
+               return nil
+       }
+
+       // We are copying volumes between storage pools so use migration system 
as it will be able
+       // to negotiate a common transfer method between pool types.
        // Create in-memory pipe pair to simulate a connection between the 
sender and receiver.
        aEnd, bEnd := memorypipe.NewPipePair()
 
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to