[lxc-devel] [lxd/master] lxd/patches: Fix handling of containers-snapshots
stgraber on Github
lxc-bot at linuxcontainers.org
Thu Jun 13 14:24:34 UTC 2019
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 370 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190613/a04ae8c6/attachment.bin>
-------------- next part --------------
From 5b213d1b7de7790f7d0d801151953caf281dcc27 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 13 Jun 2019 10:23:15 -0400
Subject: [PATCH] lxd/patches: Fix handling of containers-snapshots
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Closes #5828
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
lxd/patches.go | 36 +++++++++++++++++++++++++-----------
1 file changed, 25 insertions(+), 11 deletions(-)
diff --git a/lxd/patches.go b/lxd/patches.go
index 931ef2242b..8b7cf993a8 100644
--- a/lxd/patches.go
+++ b/lxd/patches.go
@@ -70,6 +70,8 @@ var patches = []patch{
{name: "storage_api_rename_container_snapshots_dir", run: patchStorageApiRenameContainerSnapshotsDir},
{name: "storage_api_rename_container_snapshots_links", run: patchStorageApiUpdateContainerSnapshots},
{name: "fix_lvm_pool_volume_names", run: patchRenameCustomVolumeLVs},
+ {name: "storage_api_rename_container_snapshots_dir_again", run: patchStorageApiRenameContainerSnapshotsDir},
+ {name: "storage_api_rename_container_snapshots_links_again", run: patchStorageApiUpdateContainerSnapshots},
}
type patch struct {
@@ -3256,23 +3258,35 @@ func patchMoveBackups(name string, d *Daemon) error {
}
func patchStorageApiRenameContainerSnapshotsDir(name string, d *Daemon) error {
- storagePoolsPath := shared.VarPath("storage-pools")
- storagePoolsDir, err := os.Open(storagePoolsPath)
- if err != nil {
+ pools, err := d.cluster.StoragePools()
+ if err != nil && err == db.ErrNoSuchObject {
+ // No pool was configured in the previous update. So we're on a
+ // pristine LXD instance.
+ return nil
+ } else if err != nil {
+ // Database is screwed.
+ logger.Errorf("Failed to query database: %s", err)
return err
}
- // Get a list of all storage pools.
- storagePoolNames, err := storagePoolsDir.Readdirnames(-1)
- storagePoolsDir.Close()
- if err != nil {
- return err
- }
+ for _, poolName := range pools {
+ pool, err := storagePoolInit(d.State(), poolName)
+ if err != nil {
+ return err
+ }
+
+ ourMount, err := pool.StoragePoolMount()
+ if err != nil {
+ return err
+ }
+
+ if ourMount {
+ defer pool.StoragePoolUmount()
+ }
- for _, poolName := range storagePoolNames {
containerSnapshotDirOld := shared.VarPath("storage-pools", poolName, "snapshots")
containerSnapshotDirNew := shared.VarPath("storage-pools", poolName, "containers-snapshots")
- err := shared.FileMove(containerSnapshotDirOld, containerSnapshotDirNew)
+ err = shared.FileMove(containerSnapshotDirOld, containerSnapshotDirNew)
if err != nil {
if os.IsNotExist(err) {
continue
More information about the lxc-devel
mailing list