The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/6709
This e-mail was sent by the LXC bot, direct replies will not reach the author unless they happen to be subscribed to this list. === Description (from pull-request) === Fixes LXD 2.0 to 3.19 upgrade issues. Signed-off-by: Stéphane Graber <stgra...@ubuntu.com>
From 4ea3592bc9cd4e0d467cfb5474e729b385748477 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgra...@ubuntu.com> Date: Tue, 14 Jan 2020 13:31:18 -0500 Subject: [PATCH] lxd/db: Ensure zfs.pool_name is set MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes LXD 2.0 to 3.19 upgrade issues. Signed-off-by: Stéphane Graber <stgra...@ubuntu.com> --- lxd/db/cluster/update.go | 43 ++++++++++++++++++++++++++++++++++++++++ lxd/patches.go | 2 +- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/lxd/db/cluster/update.go b/lxd/db/cluster/update.go index e468aa1fc0..1466f9f13e 100644 --- a/lxd/db/cluster/update.go +++ b/lxd/db/cluster/update.go @@ -58,6 +58,49 @@ var updates = map[int]schema.Update{ 20: updateFromV19, 21: updateFromV20, 22: updateFromV21, + 23: updateFromV22, +} + +// The zfs.pool_name config key is required for ZFS to function. +func updateFromV22(tx *sql.Tx) error { + // Fetch the IDs of all existing nodes. + nodeIDs, err := query.SelectIntegers(tx, "SELECT id FROM nodes") + if err != nil { + return errors.Wrap(err, "Failed to get IDs of current nodes") + } + + // Fetch the IDs of all existing zfs pools. + poolIDs, err := query.SelectIntegers(tx, `SELECT id FROM storage_pools WHERE driver='zfs'`) + if err != nil { + return errors.Wrap(err, "Failed to get IDs of current zfs pools") + } + + for _, poolID := range poolIDs { + for _, nodeID := range nodeIDs { + // Fetch the config for this zfs pool. + config, err := query.SelectConfig(tx, "storage_pools_config", "storage_pool_id=? AND node_id=?", poolID, nodeID) + if err != nil { + return errors.Wrap(err, "Failed to fetch of zfs pool config") + } + + // Check if already set. + _, ok := config["zfs.pool_name"] + if ok { + continue + } + + // Add zfs.pool_name config entry + _, err = tx.Exec(` +INSERT INTO storage_pools_config(storage_pool_id, node_id, key, value) +SELECT ?, ?, 'zfs.pool_name', name FROM storage_pools WHERE id=? +`, poolID, nodeID, poolID) + if err != nil { + return errors.Wrap(err, "Failed to create zfs.pool_name node config") + } + } + } + + return nil } // Fix "images_profiles" table (missing UNIQUE) diff --git a/lxd/patches.go b/lxd/patches.go index 35bb9e7f9d..c5f7a1b5e7 100644 --- a/lxd/patches.go +++ b/lxd/patches.go @@ -1528,6 +1528,7 @@ func upgradeFromStorageTypeZfs(name string, d *Daemon, defaultPoolName string, d return err } } else if err == db.ErrNoSuchObject { // Likely a pristine upgrade. + poolConfig["zfs.pool_name"] = defaultPoolName if shared.PathExists(oldLoopFilePath) { // This is a loop file pool. poolConfig["source"] = shared.VarPath("disks", poolName+".img") @@ -1541,7 +1542,6 @@ func upgradeFromStorageTypeZfs(name string, d *Daemon, defaultPoolName string, d // to refer to the on-disk name of the pool in the // "source" propert and not the db name of the pool. poolConfig["source"] = defaultPoolName - poolConfig["zfs.pool_name"] = defaultPoolName } // Querying the size of a storage pool only makes sense when it
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel