[lxc-devel] [lxd/master] lxd: Fix automatic storage volume snapshots

monstermunchkin on Github lxc-bot at linuxcontainers.org
Mon Aug 10 16:27:10 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 480 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200810/1ab7cd83/attachment.bin>
-------------- next part --------------
From 98c905c47ed70bb788628e35984bc50e7324eb7c Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Mon, 10 Aug 2020 18:24:00 +0200
Subject: [PATCH] lxd: Fix automatic storage volume snapshots

This fixes scheduled storage volume snapshots. Instead of only creating
database entries, it actually creates snapshots.

Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
 lxd/storage_volumes_snapshot.go | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/lxd/storage_volumes_snapshot.go b/lxd/storage_volumes_snapshot.go
index dfd604df39..c47fb36336 100644
--- a/lxd/storage_volumes_snapshot.go
+++ b/lxd/storage_volumes_snapshot.go
@@ -714,8 +714,6 @@ func autoCreateCustomVolumeSnapshots(ctx context.Context, d *Daemon, volumes []d
 				return
 			}
 
-			snapshotName = fmt.Sprintf("%s%s%s", v.Name, shared.SnapshotDelimiter, snapshotName)
-
 			expiry, err := shared.GetSnapshotExpiry(time.Now(), v.Config["snapshots.expiry"])
 			if err != nil {
 				logger.Error("Error getting expiry date", log.Ctx{"err": err, "volume": v})
@@ -723,17 +721,16 @@ func autoCreateCustomVolumeSnapshots(ctx context.Context, d *Daemon, volumes []d
 				return
 			}
 
-			// Get pool ID
-			poolID, err := d.cluster.GetStoragePoolID(v.PoolName)
+			pool, err := storagePools.GetPoolByName(d.State(), v.PoolName)
 			if err != nil {
-				logger.Error("Error retrieving pool ID", log.Ctx{"err": err, "pool": v.PoolName})
+				logger.Error("Error retrieving pool", log.Ctx{"err": err, "pool": v.PoolName})
 				ch <- nil
 				return
 			}
 
-			_, err = d.cluster.CreateStorageVolumeSnapshot(v.ProjectName, snapshotName, v.Description, db.StoragePoolVolumeTypeCustom, poolID, v.Config, expiry)
+			err = pool.CreateCustomVolumeSnapshot(v.ProjectName, v.Name, snapshotName, expiry, nil)
 			if err != nil {
-				logger.Error("Error creating volume snaphost", log.Ctx{"err": err, "volume": v})
+				logger.Error("Error creating volume snapshot", log.Ctx{"err": err, "volume": v})
 			}
 
 			ch <- nil


More information about the lxc-devel mailing list