[lxc-devel] [lxd/master] patches: ensure existing pool config is kept
brauner on Github
lxc-bot at linuxcontainers.org
Sun Mar 12 14:52:48 UTC 2017
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 637 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170312/d94f5482/attachment.bin>
-------------- next part --------------
From fe20d57f426a56e15be5af5fc89c866a0b392323 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sun, 12 Mar 2017 15:49:50 +0100
Subject: [PATCH] patches: ensure existing pool config is kept
When the daemon gets killed mid-upgrade and the storage_api patch doesn't
successfully complete but a storage pool entry was already created in the db it
is vital that we do not alter the current config. We should only alter it when
it is not set in the first place.
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
lxd/patches.go | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/lxd/patches.go b/lxd/patches.go
index 93068f8..28a2bf6 100644
--- a/lxd/patches.go
+++ b/lxd/patches.go
@@ -296,7 +296,7 @@ func upgradeFromStorageTypeBtrfs(name string, d *Daemon, defaultPoolName string,
// Get the pool ID as we need it for storage volume creation.
// (Use a tmp variable as Go's scoping is freaking me out.)
- tmp, err := dbStoragePoolGetID(d.db, defaultPoolName)
+ tmp, pool, err := dbStoragePoolGet(d.db, defaultPoolName)
if err != nil {
shared.LogErrorf("Failed to query database: %s.", err)
return err
@@ -306,7 +306,10 @@ func upgradeFromStorageTypeBtrfs(name string, d *Daemon, defaultPoolName string,
// Update the pool configuration on a post LXD 2.9.1 instance
// that still runs this upgrade code because of a partial
// upgrade.
- err = dbStoragePoolUpdate(d.db, defaultPoolName, poolConfig)
+ if pool.Config == nil {
+ pool.Config = poolConfig
+ }
+ err = dbStoragePoolUpdate(d.db, defaultPoolName, pool.Config)
if err != nil {
return err
}
@@ -590,7 +593,7 @@ func upgradeFromStorageTypeDir(name string, d *Daemon, defaultPoolName string, d
// Get the pool ID as we need it for storage volume creation.
// (Use a tmp variable as Go's scoping is freaking me out.)
- tmp, err := dbStoragePoolGetID(d.db, defaultPoolName)
+ tmp, pool, err := dbStoragePoolGet(d.db, defaultPoolName)
if err != nil {
shared.LogErrorf("Failed to query database: %s.", err)
return err
@@ -600,7 +603,10 @@ func upgradeFromStorageTypeDir(name string, d *Daemon, defaultPoolName string, d
// Update the pool configuration on a post LXD 2.9.1 instance
// that still runs this upgrade code because of a partial
// upgrade.
- err = dbStoragePoolUpdate(d.db, defaultPoolName, poolConfig)
+ if pool.Config == nil {
+ pool.Config = poolConfig
+ }
+ err = dbStoragePoolUpdate(d.db, defaultPoolName, pool.Config)
if err != nil {
return err
}
@@ -880,7 +886,7 @@ func upgradeFromStorageTypeLvm(name string, d *Daemon, defaultPoolName string, d
// Get the pool ID as we need it for storage volume creation.
// (Use a tmp variable as Go's scoping is freaking me out.)
- tmp, err := dbStoragePoolGetID(d.db, defaultPoolName)
+ tmp, pool, err := dbStoragePoolGet(d.db, defaultPoolName)
if err != nil {
shared.LogErrorf("Failed to query database: %s.", err)
return err
@@ -890,7 +896,10 @@ func upgradeFromStorageTypeLvm(name string, d *Daemon, defaultPoolName string, d
// Update the pool configuration on a post LXD 2.9.1 instance
// that still runs this upgrade code because of a partial
// upgrade.
- err = dbStoragePoolUpdate(d.db, defaultPoolName, poolConfig)
+ if pool.Config == nil {
+ pool.Config = poolConfig
+ }
+ err = dbStoragePoolUpdate(d.db, defaultPoolName, pool.Config)
if err != nil {
return err
}
More information about the lxc-devel
mailing list