[lxc-devel] [lxd/master] More generic storage functions

stgraber on Github lxc-bot at linuxcontainers.org
Thu Dec 19 05:18:45 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/20191218/b4574846/attachment.bin>
-------------- next part --------------
From 9f2aef3916521e5001af7342f6e11c4d1e79d212 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Wed, 18 Dec 2019 18:17:09 -0500
Subject: [PATCH 1/4] lxd/storage/drivers: Export Name and Logger
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/storage/drivers/driver_common.go | 10 ++++++++++
 lxd/storage/drivers/interface.go     |  6 +++++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/lxd/storage/drivers/driver_common.go b/lxd/storage/drivers/driver_common.go
index 5f9ce8560b..cd85e90f98 100644
--- a/lxd/storage/drivers/driver_common.go
+++ b/lxd/storage/drivers/driver_common.go
@@ -106,6 +106,16 @@ func (d *common) MigrationTypes(contentType ContentType, refresh bool) []migrati
 	}
 }
 
+// Name returns the pool name.
+func (d *common) Name() string {
+	return d.name
+}
+
+// Logger returns the current logger.
+func (d *common) Logger() logger.Logger {
+	return d.logger
+}
+
 // Config returns the storage pool config (as a copy, so not modifiable).
 func (d *common) Config() map[string]string {
 	confCopy := make(map[string]string, len(d.config))
diff --git a/lxd/storage/drivers/interface.go b/lxd/storage/drivers/interface.go
index 26209c9dc9..d05f47367d 100644
--- a/lxd/storage/drivers/interface.go
+++ b/lxd/storage/drivers/interface.go
@@ -21,10 +21,14 @@ type driver interface {
 // Driver represents a low-level storage driver.
 type Driver interface {
 	// Internal.
-	Config() map[string]string
 	Info() Info
 	HasVolume(vol Volume) bool
 
+	// Export struct details.
+	Name() string
+	Config() map[string]string
+	Logger() logger.Logger
+
 	// Pool.
 	Create() error
 	Delete(op *operations.Operation) error

From c2c4608c324a1509bbdd49e87580b4420b074e09 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Wed, 18 Dec 2019 16:54:01 -0500
Subject: [PATCH 2/4] lxd/storage/drivers: Introduce genericCopyVolume
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This function can be use for CopyVolume or RefreshVolume and is
structured around what was in the directory driver.

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/storage/drivers/driver_dir_utils.go       | 96 -------------------
 lxd/storage/drivers/driver_dir_volumes.go     |  5 +-
 .../drivers/{backups.go => generic.go}        | 84 ++++++++++++++++
 3 files changed, 87 insertions(+), 98 deletions(-)
 rename lxd/storage/drivers/{backups.go => generic.go} (51%)

diff --git a/lxd/storage/drivers/driver_dir_utils.go b/lxd/storage/drivers/driver_dir_utils.go
index 37471104f2..aee2a289d6 100644
--- a/lxd/storage/drivers/driver_dir_utils.go
+++ b/lxd/storage/drivers/driver_dir_utils.go
@@ -2,12 +2,8 @@ package drivers
 
 import (
 	"fmt"
-	"os"
 
-	"github.com/lxc/lxd/lxd/operations"
-	"github.com/lxc/lxd/lxd/rsync"
 	"github.com/lxc/lxd/lxd/storage/quota"
-	"github.com/lxc/lxd/shared"
 	log "github.com/lxc/lxd/shared/log15"
 	"github.com/lxc/lxd/shared/units"
 )
@@ -22,98 +18,6 @@ func (d *dir) withoutGetVolID() Driver {
 	return newDriver
 }
 
-// copyVolume copies a volume and its specific snapshots.
-func (d *dir) copyVolume(vol Volume, srcVol Volume, srcSnapshots []Volume, op *operations.Operation) error {
-	if vol.contentType != ContentTypeFS || srcVol.contentType != ContentTypeFS {
-		return fmt.Errorf("Content type not supported")
-	}
-
-	bwlimit := d.config["rsync.bwlimit"]
-
-	// Get the volume ID for the new volumes, which is used to set project quota.
-	volID, err := d.getVolID(vol.volType, vol.name)
-	if err != nil {
-		return err
-	}
-
-	// Create the main volume path.
-	volPath := vol.MountPath()
-	err = vol.EnsureMountPath()
-	if err != nil {
-		return err
-	}
-
-	// Create slice of snapshots created if revert needed later.
-	revertSnaps := []string{}
-	defer func() {
-		if revertSnaps == nil {
-			return
-		}
-
-		// Remove any paths created if we are reverting.
-		for _, snapName := range revertSnaps {
-			fullSnapName := GetSnapshotVolumeName(vol.name, snapName)
-			snapVol := NewVolume(d, d.name, vol.volType, vol.contentType, fullSnapName, vol.config)
-			d.DeleteVolumeSnapshot(snapVol, op)
-		}
-
-		os.RemoveAll(volPath)
-	}()
-
-	// Ensure the volume is mounted.
-	err = vol.MountTask(func(mountPath string, op *operations.Operation) error {
-		// If copying snapshots is indicated, check the source isn't itself a snapshot.
-		if len(srcSnapshots) > 0 && !srcVol.IsSnapshot() {
-			for _, srcSnapshot := range srcSnapshots {
-				_, snapName, _ := shared.InstanceGetParentAndSnapshotName(srcSnapshot.name)
-
-				// Mount the source snapshot.
-				err = srcSnapshot.MountTask(func(srcMountPath string, op *operations.Operation) error {
-					// Copy the snapshot.
-					_, err = rsync.LocalCopy(srcMountPath, mountPath, bwlimit, true)
-					return err
-				}, op)
-
-				fullSnapName := GetSnapshotVolumeName(vol.name, snapName)
-				snapVol := NewVolume(d, d.name, vol.volType, vol.contentType, fullSnapName, vol.config)
-
-				// Create the snapshot itself.
-				err = d.CreateVolumeSnapshot(snapVol, op)
-				if err != nil {
-					return err
-				}
-
-				// Setup the revert.
-				revertSnaps = append(revertSnaps, snapName)
-			}
-		}
-
-		// Initialise the volume's quota using the volume ID.
-		err = d.initQuota(volPath, volID)
-		if err != nil {
-			return err
-		}
-
-		// Set the quota if specified in volConfig or pool config.
-		err = d.setQuota(volPath, volID, vol.config["size"])
-		if err != nil {
-			return err
-		}
-
-		// Copy source to destination (mounting each volume if needed).
-		return srcVol.MountTask(func(srcMountPath string, op *operations.Operation) error {
-			_, err := rsync.LocalCopy(srcMountPath, mountPath, bwlimit, true)
-			return err
-		}, op)
-	}, op)
-	if err != nil {
-		return err
-	}
-
-	revertSnaps = nil // Don't revert.
-	return nil
-}
-
 // setupInitialQuota enables quota on a new volume and sets with an initial quota from config.
 // Returns a revert function that can be used to remove the quota if there is a subsequent error.
 func (d *dir) setupInitialQuota(vol Volume) (func(), error) {
diff --git a/lxd/storage/drivers/driver_dir_volumes.go b/lxd/storage/drivers/driver_dir_volumes.go
index 19d5c8903f..d7e1e1aa1e 100644
--- a/lxd/storage/drivers/driver_dir_volumes.go
+++ b/lxd/storage/drivers/driver_dir_volumes.go
@@ -120,7 +120,8 @@ func (d *dir) CreateVolumeFromCopy(vol Volume, srcVol Volume, copySnapshots bool
 		}
 	}
 
-	return d.copyVolume(vol, srcVol, srcSnapshots, op)
+	// Run the generic copy.
+	return genericCopyVolume(d, d.setupInitialQuota, vol, srcVol, srcSnapshots, op)
 }
 
 // CreateVolumeFromMigration creates a volume being sent via a migration.
@@ -253,7 +254,7 @@ func (d *dir) CreateVolumeFromMigration(vol Volume, conn io.ReadWriteCloser, vol
 
 // RefreshVolume provides same-pool volume and specific snapshots syncing functionality.
 func (d *dir) RefreshVolume(vol Volume, srcVol Volume, srcSnapshots []Volume, op *operations.Operation) error {
-	return d.copyVolume(vol, srcVol, srcSnapshots, op)
+	return genericCopyVolume(d, d.setupInitialQuota, vol, srcVol, srcSnapshots, op)
 }
 
 // DeleteVolume deletes a volume of the storage device. If any snapshots of the volume remain then
diff --git a/lxd/storage/drivers/backups.go b/lxd/storage/drivers/generic.go
similarity index 51%
rename from lxd/storage/drivers/backups.go
rename to lxd/storage/drivers/generic.go
index 2b8fa407af..9ac19e59ad 100644
--- a/lxd/storage/drivers/backups.go
+++ b/lxd/storage/drivers/generic.go
@@ -3,11 +3,95 @@ package drivers
 import (
 	"fmt"
 	"io"
+	"os"
 
 	"github.com/lxc/lxd/lxd/operations"
+	"github.com/lxc/lxd/lxd/rsync"
 	"github.com/lxc/lxd/shared"
 )
 
+// genericCopyVolume copies a volume and its snapshots using a non-optimized method.
+func genericCopyVolume(d Driver, applyQuota func(vol Volume) (func(), error), vol Volume, srcVol Volume, srcSnapshots []Volume, op *operations.Operation) error {
+	if vol.contentType != ContentTypeFS || srcVol.contentType != ContentTypeFS {
+		return fmt.Errorf("Content type not supported")
+	}
+
+	bwlimit := d.Config()["rsync.bwlimit"]
+
+	// Create the main volume path.
+	volPath := vol.MountPath()
+	err := vol.EnsureMountPath()
+	if err != nil {
+		return err
+	}
+
+	// Create slice of snapshots created if revert needed later.
+	revertSnaps := []string{}
+	defer func() {
+		if revertSnaps == nil {
+			return
+		}
+
+		// Remove any paths created if we are reverting.
+		for _, snapName := range revertSnaps {
+			fullSnapName := GetSnapshotVolumeName(vol.name, snapName)
+			snapVol := NewVolume(d, d.Name(), vol.volType, vol.contentType, fullSnapName, vol.config)
+			d.DeleteVolumeSnapshot(snapVol, op)
+		}
+
+		os.RemoveAll(volPath)
+	}()
+
+	// Ensure the volume is mounted.
+	err = vol.MountTask(func(mountPath string, op *operations.Operation) error {
+		// If copying snapshots is indicated, check the source isn't itself a snapshot.
+		if len(srcSnapshots) > 0 && !srcVol.IsSnapshot() {
+			for _, srcSnapshot := range srcSnapshots {
+				_, snapName, _ := shared.InstanceGetParentAndSnapshotName(srcSnapshot.name)
+
+				// Mount the source snapshot.
+				err = srcSnapshot.MountTask(func(srcMountPath string, op *operations.Operation) error {
+					// Copy the snapshot.
+					_, err = rsync.LocalCopy(srcMountPath, mountPath, bwlimit, true)
+					return err
+				}, op)
+
+				fullSnapName := GetSnapshotVolumeName(vol.name, snapName)
+				snapVol := NewVolume(d, d.Name(), vol.volType, vol.contentType, fullSnapName, vol.config)
+
+				// Create the snapshot itself.
+				err = d.CreateVolumeSnapshot(snapVol, op)
+				if err != nil {
+					return err
+				}
+
+				// Setup the revert.
+				revertSnaps = append(revertSnaps, snapName)
+			}
+		}
+
+		// Apply some quotas if needed.
+		if applyQuota != nil {
+			_, err := applyQuota(vol)
+			if err != nil {
+				return err
+			}
+		}
+
+		// Copy source to destination (mounting each volume if needed).
+		return srcVol.MountTask(func(srcMountPath string, op *operations.Operation) error {
+			_, err := rsync.LocalCopy(srcMountPath, mountPath, bwlimit, true)
+			return err
+		}, op)
+	}, op)
+	if err != nil {
+		return err
+	}
+
+	revertSnaps = nil // Don't revert.
+	return nil
+}
+
 // genericBackupUnpack unpacks a non-optimized backup tarball through a storage driver.
 func genericBackupUnpack(d Driver, poolName string, vol Volume, snapshots []string, srcData io.ReadSeeker, op *operations.Operation) (func(vol Volume) error, func(), error) {
 	revert := true

From 089047f22e8f694ca7c504d8f7f4867c5ec757cb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Wed, 18 Dec 2019 18:17:53 -0500
Subject: [PATCH 3/4] lxd/storage/drivers: Introduce
 genericCreateVolumeFromMigration
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/storage/drivers/driver_dir_volumes.go | 119 +---------------------
 lxd/storage/drivers/generic.go            | 104 +++++++++++++++++++
 2 files changed, 105 insertions(+), 118 deletions(-)

diff --git a/lxd/storage/drivers/driver_dir_volumes.go b/lxd/storage/drivers/driver_dir_volumes.go
index d7e1e1aa1e..5203d156a2 100644
--- a/lxd/storage/drivers/driver_dir_volumes.go
+++ b/lxd/storage/drivers/driver_dir_volumes.go
@@ -11,8 +11,6 @@ import (
 	"github.com/lxc/lxd/lxd/rsync"
 	"github.com/lxc/lxd/lxd/storage/quota"
 	"github.com/lxc/lxd/shared"
-	"github.com/lxc/lxd/shared/ioprogress"
-	log "github.com/lxc/lxd/shared/log15"
 )
 
 // CreateVolume creates an empty volume and can optionally fill it by executing the supplied
@@ -134,122 +132,7 @@ func (d *dir) CreateVolumeFromMigration(vol Volume, conn io.ReadWriteCloser, vol
 		return fmt.Errorf("Migration type not supported")
 	}
 
-	// Get the volume ID for the new volumes, which is used to set project quota.
-	volID, err := d.getVolID(vol.volType, vol.name)
-	if err != nil {
-		return err
-	}
-
-	// Create the main volume path.
-	volPath := vol.MountPath()
-	err = vol.EnsureMountPath()
-	if err != nil {
-		return err
-	}
-
-	// Create slice of snapshots created if revert needed later.
-	revertSnaps := []string{}
-	defer func() {
-		if revertSnaps == nil {
-			return
-		}
-
-		// Remove any paths created if we are reverting.
-		for _, snapName := range revertSnaps {
-			fullSnapName := GetSnapshotVolumeName(vol.name, snapName)
-			snapVol := NewVolume(d, d.name, vol.volType, vol.contentType, fullSnapName, vol.config)
-			d.DeleteVolumeSnapshot(snapVol, op)
-		}
-
-		os.RemoveAll(volPath)
-	}()
-
-	// Ensure the volume is mounted.
-	err = vol.MountTask(func(mountPath string, op *operations.Operation) error {
-		path := shared.AddSlash(mountPath)
-
-		// Run the volume pre-filler function if supplied.
-		if preFiller != nil && preFiller.Fill != nil {
-			d.logger.Debug("Running pre-filler function", log.Ctx{"volume": vol.name, "path": path})
-			err = preFiller.Fill(path, "")
-			if err != nil {
-				return err
-			}
-			d.logger.Debug("Finished pre-filler function", log.Ctx{"volume": vol.name})
-		}
-
-		// Snapshots are sent first by the sender, so create these first.
-		for _, snapName := range volTargetArgs.Snapshots {
-			// Receive the snapshot
-			var wrapper *ioprogress.ProgressTracker
-			if volTargetArgs.TrackProgress {
-				wrapper = migration.ProgressTracker(op, "fs_progress", snapName)
-			}
-
-			d.logger.Debug("Receiving volume", log.Ctx{"volume": vol.name, "snapshot": snapName, "path": path})
-			err = rsync.Recv(path, conn, wrapper, volTargetArgs.MigrationType.Features)
-			if err != nil {
-				return err
-			}
-
-			// Create the snapshot itself.
-			fullSnapshotName := GetSnapshotVolumeName(vol.name, snapName)
-			snapVol := NewVolume(d, d.name, vol.volType, vol.contentType, fullSnapshotName, vol.config)
-
-			err = d.CreateVolumeSnapshot(snapVol, op)
-			if err != nil {
-				return err
-			}
-
-			// Setup the revert.
-			revertSnaps = append(revertSnaps, snapName)
-		}
-
-		// Initialise the volume's quota using the volume ID.
-		err = d.initQuota(volPath, volID)
-		if err != nil {
-			return err
-		}
-
-		// Set the quota if specified in volConfig or pool config.
-		err = d.setQuota(volPath, volID, vol.config["size"])
-		if err != nil {
-			return err
-		}
-
-		// Receive the main volume from sender.
-		var wrapper *ioprogress.ProgressTracker
-		if volTargetArgs.TrackProgress {
-			wrapper = migration.ProgressTracker(op, "fs_progress", vol.name)
-		}
-
-		d.logger.Debug("Receiving volume", log.Ctx{"volume": vol.name, "path": path})
-		err = rsync.Recv(path, conn, wrapper, volTargetArgs.MigrationType.Features)
-		if err != nil {
-			return err
-		}
-
-		// Receive the final main volume sync if needed.
-		if volTargetArgs.Live {
-			if volTargetArgs.TrackProgress {
-				wrapper = migration.ProgressTracker(op, "fs_progress", vol.name)
-			}
-
-			d.logger.Debug("Receiving volume (final stage)", log.Ctx{"vol": vol.name, "path": path})
-			err = rsync.Recv(path, conn, wrapper, volTargetArgs.MigrationType.Features)
-			if err != nil {
-				return err
-			}
-		}
-
-		return nil
-	}, op)
-	if err != nil {
-		return err
-	}
-
-	revertSnaps = nil
-	return nil
+	return genericCreateVolumeFromMigration(d, d.setupInitialQuota, vol, conn, volTargetArgs, preFiller, op)
 }
 
 // RefreshVolume provides same-pool volume and specific snapshots syncing functionality.
diff --git a/lxd/storage/drivers/generic.go b/lxd/storage/drivers/generic.go
index 9ac19e59ad..129763f68b 100644
--- a/lxd/storage/drivers/generic.go
+++ b/lxd/storage/drivers/generic.go
@@ -5,9 +5,12 @@ import (
 	"io"
 	"os"
 
+	"github.com/lxc/lxd/lxd/migration"
 	"github.com/lxc/lxd/lxd/operations"
 	"github.com/lxc/lxd/lxd/rsync"
 	"github.com/lxc/lxd/shared"
+	"github.com/lxc/lxd/shared/ioprogress"
+	log "github.com/lxc/lxd/shared/log15"
 )
 
 // genericCopyVolume copies a volume and its snapshots using a non-optimized method.
@@ -92,6 +95,107 @@ func genericCopyVolume(d Driver, applyQuota func(vol Volume) (func(), error), vo
 	return nil
 }
 
+// genericCreateVolumeFromMigration receives a volume and its snapshots over a non-optimized method.
+func genericCreateVolumeFromMigration(d Driver, applyQuota func(vol Volume) (func(), error), vol Volume, conn io.ReadWriteCloser, volTargetArgs migration.VolumeTargetArgs, preFiller *VolumeFiller, op *operations.Operation) error {
+	// Create the main volume path.
+	if !volTargetArgs.Refresh {
+		err := d.CreateVolume(vol, preFiller, op)
+		if err != nil {
+			return err
+		}
+	}
+
+	// Create slice of snapshots created if revert needed later.
+	revertSnaps := []string{}
+	defer func() {
+		if revertSnaps == nil {
+			return
+		}
+
+		// Remove any paths created if we are reverting.
+		for _, snapName := range revertSnaps {
+			fullSnapName := GetSnapshotVolumeName(vol.Name(), snapName)
+			snapVol := NewVolume(d, d.Name(), vol.volType, vol.contentType, fullSnapName, vol.config)
+			d.DeleteVolumeSnapshot(snapVol, op)
+		}
+
+		d.DeleteVolume(vol, op)
+	}()
+
+	// Ensure the volume is mounted.
+	err := vol.MountTask(func(mountPath string, op *operations.Operation) error {
+		path := shared.AddSlash(mountPath)
+
+		// Snapshots are sent first by the sender, so create these first.
+		for _, snapName := range volTargetArgs.Snapshots {
+			// Receive the snapshot
+			var wrapper *ioprogress.ProgressTracker
+			if volTargetArgs.TrackProgress {
+				wrapper = migration.ProgressTracker(op, "fs_progress", snapName)
+			}
+
+			d.Logger().Debug("Receiving volume", log.Ctx{"volume": vol.name, "snapshot": snapName, "path": path})
+			err := rsync.Recv(path, conn, wrapper, volTargetArgs.MigrationType.Features)
+			if err != nil {
+				return err
+			}
+
+			// Create the snapshot itself.
+			fullSnapshotName := GetSnapshotVolumeName(vol.name, snapName)
+			snapVol := NewVolume(d, d.Name(), vol.volType, vol.contentType, fullSnapshotName, vol.config)
+
+			err = d.CreateVolumeSnapshot(snapVol, op)
+			if err != nil {
+				return err
+			}
+
+			// Setup the revert.
+			revertSnaps = append(revertSnaps, snapName)
+		}
+
+		// Apply quotas.
+		if applyQuota != nil {
+			_, err := applyQuota(vol)
+			if err != nil {
+				return err
+			}
+		}
+
+		// Receive the main volume from sender.
+		var wrapper *ioprogress.ProgressTracker
+		if volTargetArgs.TrackProgress {
+			wrapper = migration.ProgressTracker(op, "fs_progress", vol.name)
+		}
+
+		d.Logger().Debug("Receiving volume", log.Ctx{"volume": vol.name, "path": path})
+		err := rsync.Recv(path, conn, wrapper, volTargetArgs.MigrationType.Features)
+		if err != nil {
+			return err
+		}
+
+		// Receive the final main volume sync if needed.
+		if volTargetArgs.Live {
+			if volTargetArgs.TrackProgress {
+				wrapper = migration.ProgressTracker(op, "fs_progress", vol.name)
+			}
+
+			d.Logger().Debug("Receiving volume (final stage)", log.Ctx{"vol": vol.name, "path": path})
+			err = rsync.Recv(path, conn, wrapper, volTargetArgs.MigrationType.Features)
+			if err != nil {
+				return err
+			}
+		}
+
+		return nil
+	}, op)
+	if err != nil {
+		return err
+	}
+
+	revertSnaps = nil
+	return nil
+}
+
 // genericBackupUnpack unpacks a non-optimized backup tarball through a storage driver.
 func genericBackupUnpack(d Driver, poolName string, vol Volume, snapshots []string, srcData io.ReadSeeker, op *operations.Operation) (func(vol Volume) error, func(), error) {
 	revert := true

From 394c49cfc45dbc115386a4a781029236f2db6e92 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Wed, 18 Dec 2019 18:23:20 -0500
Subject: [PATCH 4/4] lxd/storage/drivers: Simplify genericBackupUnpack
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/storage/drivers/driver_dir_volumes.go | 2 +-
 lxd/storage/drivers/generic.go            | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/lxd/storage/drivers/driver_dir_volumes.go b/lxd/storage/drivers/driver_dir_volumes.go
index 5203d156a2..bda0866ef1 100644
--- a/lxd/storage/drivers/driver_dir_volumes.go
+++ b/lxd/storage/drivers/driver_dir_volumes.go
@@ -79,7 +79,7 @@ func (d *dir) CreateVolume(vol Volume, filler *VolumeFiller, op *operations.Oper
 // CreateVolumeFromBackup restores a backup tarball onto the storage device.
 func (d *dir) CreateVolumeFromBackup(vol Volume, snapshots []string, srcData io.ReadSeeker, optimizedStorage bool, op *operations.Operation) (func(vol Volume) error, func(), error) {
 	// Run the generic backup unpacker
-	postHook, revertHook, err := genericBackupUnpack(d.withoutGetVolID(), d.name, vol, snapshots, srcData, op)
+	postHook, revertHook, err := genericBackupUnpack(d.withoutGetVolID(), vol, snapshots, srcData, op)
 	if err != nil {
 		return nil, nil, err
 	}
diff --git a/lxd/storage/drivers/generic.go b/lxd/storage/drivers/generic.go
index 129763f68b..5102677e90 100644
--- a/lxd/storage/drivers/generic.go
+++ b/lxd/storage/drivers/generic.go
@@ -197,7 +197,7 @@ func genericCreateVolumeFromMigration(d Driver, applyQuota func(vol Volume) (fun
 }
 
 // genericBackupUnpack unpacks a non-optimized backup tarball through a storage driver.
-func genericBackupUnpack(d Driver, poolName string, vol Volume, snapshots []string, srcData io.ReadSeeker, op *operations.Operation) (func(vol Volume) error, func(), error) {
+func genericBackupUnpack(d Driver, vol Volume, snapshots []string, srcData io.ReadSeeker, op *operations.Operation) (func(vol Volume) error, func(), error) {
 	revert := true
 
 	// Define a revert function that will be used both to revert if an error occurs inside this
@@ -205,7 +205,7 @@ func genericBackupUnpack(d Driver, poolName string, vol Volume, snapshots []stri
 	revertHook := func() {
 		for _, snapName := range snapshots {
 			fullSnapshotName := GetSnapshotVolumeName(vol.name, snapName)
-			snapVol := NewVolume(d, poolName, vol.volType, vol.contentType, fullSnapshotName, vol.config)
+			snapVol := NewVolume(d, d.Name(), vol.volType, vol.contentType, fullSnapshotName, vol.config)
 			d.DeleteVolumeSnapshot(snapVol, op)
 		}
 
@@ -235,7 +235,7 @@ func genericBackupUnpack(d Driver, poolName string, vol Volume, snapshots []stri
 
 	if len(snapshots) > 0 {
 		// Create new snapshots directory.
-		err := createParentSnapshotDirIfMissing(poolName, vol.volType, vol.name)
+		err := createParentSnapshotDirIfMissing(d.Name(), vol.volType, vol.name)
 		if err != nil {
 			return nil, nil, err
 		}
@@ -259,7 +259,7 @@ func genericBackupUnpack(d Driver, poolName string, vol Volume, snapshots []stri
 		}
 
 		fullSnapshotName := GetSnapshotVolumeName(vol.name, snapName)
-		snapVol := NewVolume(d, poolName, vol.volType, vol.contentType, fullSnapshotName, vol.config)
+		snapVol := NewVolume(d, d.Name(), vol.volType, vol.contentType, fullSnapshotName, vol.config)
 		err = d.CreateVolumeSnapshot(snapVol, op)
 		if err != nil {
 			return nil, nil, err


More information about the lxc-devel mailing list