[lxc-devel] [lxd/master] fixed typo, created patch

AndrewElvisDeng on Github lxc-bot at linuxcontainers.org
Sun Oct 11 19:53:45 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 525 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20201011/1cfe65c8/attachment.bin>
-------------- next part --------------
From b2df1fc1618355a26659724041613a4f19f43260 Mon Sep 17 00:00:00 2001
From: Andrew Deng <adeng1433 at gmail.com>
Date: Sun, 11 Oct 2020 14:51:29 -0500
Subject: [PATCH] fixed typo, created patch

Signed-off-by: Andrew Deng <adeng1433 at 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


More information about the lxc-devel mailing list