[lxc-devel] [lxd/master] lxd: Clean up logging for expired volume snapshots

monstermunchkin on Github lxc-bot at linuxcontainers.org
Tue Mar 17 21:01:57 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 355 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200317/b408ff7a/attachment.bin>
-------------- next part --------------
From 8b31ffd6743cd9ae5fafcb21a36e714bfd6dddf5 Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Tue, 17 Mar 2020 22:00:06 +0100
Subject: [PATCH] lxd: Clean up logging for expired volume snapshots

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

diff --git a/lxd/storage_volumes_snapshot.go b/lxd/storage_volumes_snapshot.go
index 0753c0578b..e9e770ccc2 100644
--- a/lxd/storage_volumes_snapshot.go
+++ b/lxd/storage_volumes_snapshot.go
@@ -552,8 +552,19 @@ func storagePoolVolumeSnapshotTypeDelete(d *Daemon, r *http.Request) response.Re
 
 func pruneExpireCustomVolumeSnapshotsTask(d *Daemon) (task.Func, task.Schedule) {
 	f := func(ctx context.Context) {
+		// Get the list of expired custom volume snapshots.
+		expiredSnapshots, err := d.cluster.StorageVolumeSnapshotsGetExpired()
+		if err != nil {
+			logger.Error("Unable to retrieve the list of expired custom volume snapshots", log.Ctx{"err": err})
+			return
+		}
+
+		if len(expiredSnapshots) == 0 {
+			return
+		}
+
 		opRun := func(op *operations.Operation) error {
-			return pruneExpiredCustomVolumeSnapshots(ctx, d)
+			return pruneExpiredCustomVolumeSnapshots(ctx, d, expiredSnapshots)
 		}
 
 		op, err := operations.OperationCreate(d.State(), "", operations.OperationClassTask, db.OperationCustomVolumeSnapshotsExpire, nil, nil, opRun, nil, nil)
@@ -587,14 +598,8 @@ func pruneExpireCustomVolumeSnapshotsTask(d *Daemon) (task.Func, task.Schedule)
 	return f, schedule
 }
 
-func pruneExpiredCustomVolumeSnapshots(ctx context.Context, d *Daemon) error {
-	// Get the list of expired custom volume snapshots.
-	snapshots, err := d.cluster.StorageVolumeSnapshotsGetExpired()
-	if err != nil {
-		return errors.Wrap(err, "Unable to retrieve the list of expired custom volume snapshots")
-	}
-
-	for _, s := range snapshots {
+func pruneExpiredCustomVolumeSnapshots(ctx context.Context, d *Daemon, expiredSnapshots []db.StorageVolumeArgs) error {
+	for _, s := range expiredSnapshots {
 		pool, err := storagePools.GetPoolByName(d.State(), s.PoolName)
 		if err != nil {
 			return errors.Wrapf(err, "Failed to get pool %q", s.PoolName)


More information about the lxc-devel mailing list