The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/8022

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) ===
**lxd/db/storage_pools.go:**
renamed 'lvm.thinpool' to 'lvm.thinpool_name'

**lxd/patches.go**
created a patch to rename existing, incorrectly set configs from the typo

Signed-off-by: Andrew Deng <adeng1...@gmail.com>
From b2df1fc1618355a26659724041613a4f19f43260 Mon Sep 17 00:00:00 2001
From: Andrew Deng <adeng1...@gmail.com>
Date: Sun, 11 Oct 2020 14:51:29 -0500
Subject: [PATCH] fixed typo, created patch

Signed-off-by: Andrew Deng <adeng1...@gmail.com>
---
 lxd/db/storage_pools.go |  2 +-
 lxd/patches.go          | 65 +++++++++++++++++++++++++++++++++++++++--
 2 files changed, 64 insertions(+), 3 deletions(-)

diff --git a/lxd/db/storage_pools.go b/lxd/db/storage_pools.go
index e27a3d1e12..76d12693d1 100644
--- a/lxd/db/storage_pools.go
+++ b/lxd/db/storage_pools.go
@@ -885,7 +885,7 @@ var StoragePoolNodeConfigKeys = []string{
        "source",
        "volatile.initial_source",
        "zfs.pool_name",
-       "lvm.thinpool",
+       "lvm.thinpool_name",
        "lvm.vg_name",
 }
 
diff --git a/lxd/patches.go b/lxd/patches.go
index 170976700f..9ae66d6af1 100644
--- a/lxd/patches.go
+++ b/lxd/patches.go
@@ -101,6 +101,7 @@ var patches = []patch{
        {name: "clustering_drop_database_role", stage: patchPostDaemonStorage, 
run: patchClusteringDropDatabaseRole},
        {name: "network_clear_bridge_volatile_hwaddr", stage: 
patchPostDaemonStorage, run: patchNetworkCearBridgeVolatileHwaddr},
        {name: "move_backups_instances", stage: patchPostDaemonStorage, run: 
patchMoveBackupsInstances},
+       {name: "thinpool_typo_fix", stage: patchPostDaemonStorage, run: 
patchThinpoolTypoFix},
 }
 
 type patch struct {
@@ -163,8 +164,6 @@ func patchesApply(d *Daemon, stage patchStage) error {
        return nil
 }
 
-// Patches begin here
-
 // Moves backups from shared.VarPath("backups") to shared.VarPath("backups", 
"instances").
 func patchMoveBackupsInstances(name string, d *Daemon) error {
        if !shared.PathExists(shared.VarPath("backups")) {
@@ -3714,3 +3713,65 @@ func patchUpdateFromV30(_ *sql.Tx) error {
 
        return nil
 }
+
+//  renames any config incorrectly set config file entries due to the 
lvm.thinpool_name typo
+func patchThinpoolTypoFix(name string, d *Daemon) error {
+       tx, err := d.cluster.Begin()
+       if err != nil {
+               return errors.Wrap(err, "failed to begin transaction")
+       }
+
+       // 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 lvm pools.
+       poolIDs, err := query.SelectIntegers(tx, "SELECT id FROM storage_pools 
WHERE driver='lvm'")
+       if err != nil {
+               return errors.Wrap(err, "failed to get IDs of current lvm 
pools")
+       }
+
+       for _, poolID := range poolIDs {
+               // Fetch the config for this lvm pool and check if it has the
+               // lvn.thinpool_name key.
+               config, err := query.SelectConfig(
+                       tx, "storage_pools_config", "storage_pool_id=?", poolID)
+               if err != nil {
+                       return errors.Wrap(err, "failed a fetch of lvm pool 
config")
+               }
+
+               value, ok := "lvm.thinpool"
+               if !ok {
+                       continue
+               }
+
+               // Delete the current key
+               _, err = tx.Exec(`
+                       DELETE FROM storage_pools_config WHERE 
key='lvm.thinpool' AND storage_pool_id=?`, poolID)
+               if err != nil {
+                       return errors.Wrapf(err, "failed to delete %s config", 
key)
+               }
+               
+               // Add the config entry for each node
+               for _, nodeID := range nodeIDs {
+                       _, err := tx.Exec(`
+                       INSERT INTO storage_pools_config(storage_pool_id, 
node_id, key, value)
+                       VALUES(?, ?, 'lvm.thinpool_name', ?)
+                       `, poolID, curNodeID, value)
+                       if err != nil {
+                               return errors.Wrapf(err, "failed to create %s 
node config", key)
+                       }
+               }
+       }
+       }
+               
+       err = tx.Commit()
+       if err != nil {
+               return errors.Wrap(err, "failed to commit transaction")
+       }
+               
+       return err
+
+}
\ No newline at end of file
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to